File indexing completed on 2025-01-05 03:57:57
0001 /* ============================================================ 0002 * 0003 * This file is a part of digiKam project 0004 * https://www.digikam.org 0005 * 0006 * Date : 2021-09-27 0007 * Description : Showfoto stack view favorite item edit dialog 0008 * 0009 * SPDX-FileCopyrightText: 2021-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 "showfotostackviewfavoriteitemdlg.h" 0016 0017 // Qt includes 0018 0019 #include <QGridLayout> 0020 #include <QLabel> 0021 #include <QPointer> 0022 #include <QApplication> 0023 #include <QStyle> 0024 #include <QDir> 0025 #include <QFileInfo> 0026 #include <QFont> 0027 #include <QLocale> 0028 #include <QStandardPaths> 0029 #include <QDialogButtonBox> 0030 #include <QVBoxLayout> 0031 #include <QPushButton> 0032 #include <QDateTimeEdit> 0033 #include <QMimeDatabase> 0034 #include <QComboBox> 0035 #include <QMessageBox> 0036 0037 // KDE includes 0038 0039 #include <kconfiggroup.h> 0040 #include <ksharedconfig.h> 0041 #include <klocalizedstring.h> 0042 0043 #ifdef HAVE_KICONTHEMES 0044 # include <kicondialog.h> 0045 #endif 0046 0047 // Local includes 0048 0049 #include "digikam_debug.h" 0050 #include "dlayoutbox.h" 0051 #include "dexpanderbox.h" 0052 #include "drawdecoder.h" 0053 #include "dtextedit.h" 0054 #include "dxmlguiwindow.h" 0055 #include "showfotostackviewfavoritelist.h" 0056 #include "showfotostackviewfavoriteitem.h" 0057 #include "showfotostackviewlist.h" 0058 #include "showfotoitemsortsettings.h" 0059 #include "itempropertiestab.h" 0060 0061 namespace ShowFoto 0062 { 0063 0064 class Q_DECL_HIDDEN ShowfotoStackViewFavoriteItemDlg::Private 0065 { 0066 public: 0067 0068 explicit Private() 0069 : create (false), 0070 hierarchyLabel (nullptr), 0071 icon (QLatin1String("folder-favorites")), 0072 iconButton (nullptr), 0073 resetIconButton(nullptr), 0074 dateLowButton (nullptr), 0075 dateAvgButton (nullptr), 0076 dateHighButton (nullptr), 0077 buttons (nullptr), 0078 nameEdit (nullptr), 0079 descEdit (nullptr), 0080 favoriteTypeBox(nullptr), 0081 dateEdit (nullptr), 0082 urlsEdit (nullptr), 0083 descLabel (nullptr), 0084 nbImagesLabel (nullptr), 0085 dateLabel (nullptr), 0086 iconTextLabel (nullptr), 0087 urlsLabel (nullptr), 0088 helpLabel (nullptr), 0089 list (nullptr), 0090 pitem (nullptr) 0091 { 0092 } 0093 0094 bool create; 0095 0096 DAdjustableLabel* hierarchyLabel; 0097 0098 QString icon; 0099 QString originalName; 0100 0101 QPushButton* iconButton; 0102 QPushButton* resetIconButton; 0103 QPushButton* dateLowButton; 0104 QPushButton* dateAvgButton; 0105 QPushButton* dateHighButton; 0106 0107 QDialogButtonBox* buttons; 0108 0109 DTextEdit* nameEdit; 0110 DTextEdit* descEdit; 0111 QComboBox* favoriteTypeBox; 0112 QDateTimeEdit* dateEdit; 0113 DItemsList* urlsEdit; 0114 QLabel* descLabel; 0115 QLabel* nbImagesLabel; 0116 QLabel* dateLabel; 0117 QLabel* iconTextLabel; 0118 QLabel* urlsLabel; 0119 DAdjustableLabel* helpLabel; 0120 ShowfotoStackViewFavoriteList* list; 0121 ShowfotoStackViewFavoriteItem* pitem; 0122 }; 0123 0124 static Qt::SortOrder s_sortOrder(Qt::AscendingOrder); 0125 static ShowfotoStackViewList::StackViewRole s_sortRole(ShowfotoStackViewList::FileName); 0126 0127 ShowfotoStackViewFavoriteItemDlg::ShowfotoStackViewFavoriteItemDlg(ShowfotoStackViewFavoriteList* const list, 0128 bool create) 0129 : QDialog(list), 0130 d (new Private) 0131 { 0132 setModal(true); 0133 setObjectName(QLatin1String("ShowfotoStackViewFavoriteItemDlg")); 0134 0135 d->create = create; 0136 d->list = list; 0137 d->buttons = new QDialogButtonBox(QDialogButtonBox::Ok | QDialogButtonBox::Cancel | QDialogButtonBox::Help, this); 0138 d->buttons->button(QDialogButtonBox::Ok)->setDefault(true); 0139 0140 0141 QWidget* const page = new QWidget(this); 0142 QGridLayout* const grid = new QGridLayout(page); 0143 0144 // -------------------------------------------------------- 0145 0146 QLabel* const nameLabel = new QLabel(page); 0147 nameLabel->setText(i18nc("@label: favorite item title properties", "&Name:")); 0148 0149 d->nameEdit = new DTextEdit(page); 0150 d->nameEdit->setLinesVisible(1); 0151 d->nameEdit->setPlaceholderText(i18nc("@info", "Enter favorite entry name here...")); 0152 d->nameEdit->setWhatsThis(i18nc("@info", "The favorite item name which must be unique and not empty")); 0153 nameLabel->setBuddy(d->nameEdit); 0154 0155 // -------------------------------------------------------- 0156 0157 QLabel* const hierLabel = new QLabel(page); 0158 hierLabel->setText(i18nc("@label: favorite item hierarchy properties", "Hierarchy:")); 0159 0160 d->hierarchyLabel = new DAdjustableLabel(page); 0161 d->hierarchyLabel->setWhatsThis(i18nc("@info", "The favorite entry hierarchy which must be unique in tree-view")); 0162 0163 // -------------------------------------------------------- 0164 0165 QLabel* const typeLabel = new QLabel(page); 0166 typeLabel->setText(i18nc("@label: favorite entry type properties", "Type:")); 0167 0168 d->favoriteTypeBox = new QComboBox(page); 0169 d->favoriteTypeBox->addItem(i18nc("@item:inlistbox", "Favorite Folder"), ShowfotoStackViewFavoriteItem::FavoriteFolder); 0170 d->favoriteTypeBox->addItem(i18nc("@item:inlistbox", "Favorite Item"), ShowfotoStackViewFavoriteItem::FavoriteItem); 0171 d->favoriteTypeBox->setWhatsThis(i18nc("@info", 0172 "A \"Favorite Item\" is a hierarchy entry hosting advanced properties " 0173 "as date, icon, description, and images list. " 0174 "A \"Favorite Folder\" is a simple entry in the hierarchy without extra property.")); 0175 typeLabel->setBuddy(d->favoriteTypeBox); 0176 0177 // -------------------------------------------------------- 0178 0179 d->descLabel = new QLabel(page); 0180 d->descLabel->setText(i18nc("@label: favorite item caption properties", "&Description:")); 0181 0182 d->descEdit = new DTextEdit(page); 0183 d->descEdit->setLinesVisible(1); 0184 d->descEdit->setPlaceholderText(i18nc("@info", "Enter favorite item description here...")); 0185 d->descLabel->setBuddy(d->descEdit); 0186 0187 // -------------------------------------------------------- 0188 0189 d->dateLabel = new QLabel(page); 0190 d->dateLabel->setText(i18nc("@label: favorite item date properties", "&Created:")); 0191 0192 d->dateEdit = new QDateTimeEdit(QDate::currentDate(), page); 0193 d->dateEdit->setMinimumDate(QDate(1970, 1, 1)); 0194 d->dateEdit->setMaximumDate(QDate::currentDate().addDays(365)); 0195 d->dateEdit->setDisplayFormat(QLatin1String("yyyy.MM.dd")); 0196 d->dateEdit->setCalendarPopup(true); 0197 d->dateEdit->setWhatsThis(i18nc("@info", "Select favorite item date. By default, day of item creation is assigned.")); 0198 d->dateLabel->setBuddy(d->dateEdit); 0199 0200 DHBox* const buttonRow = new DHBox(page); 0201 d->dateLowButton = new QPushButton(i18nc("@action: Selects the date of the oldest image", "&Oldest"), buttonRow); 0202 d->dateLowButton->setWhatsThis(i18nc("@info", "Use this button to select the date of the oldest image from the list.")); 0203 d->dateAvgButton = new QPushButton(i18nc("@action: Calculates the average date", "&Average"), buttonRow); 0204 d->dateAvgButton->setWhatsThis(i18nc("@info", "Use this button to calculate the average date of images from the list.")); 0205 d->dateHighButton = new QPushButton(i18nc("@action: Selects the date of the newest image", "Newest"), buttonRow); 0206 d->dateHighButton->setWhatsThis(i18nc("@info", "Use this button to select the date of the newest image from the list.")); 0207 0208 // -------------------------------------------------------- 0209 0210 d->iconTextLabel = new QLabel(page); 0211 d->iconTextLabel->setText(i18nc("@label", "&Icon:")); 0212 0213 d->iconButton = new QPushButton(page); 0214 d->iconButton->setFixedSize(40, 40); 0215 d->iconButton->setIcon(QIcon::fromTheme(d->icon)); 0216 d->iconButton->setWhatsThis(i18nc("@info", "Select here the icon to use for this favorite item in tree-view.")); 0217 d->iconTextLabel->setBuddy(d->iconButton); 0218 0219 d->resetIconButton = new QPushButton(QIcon::fromTheme(QLatin1String("view-refresh")), 0220 i18nc("@action:button", "Reset"), page); 0221 d->resetIconButton->setWhatsThis(i18nc("@info", "Assign favorite item icon to default in tree-view.")); 0222 0223 #ifndef HAVE_KICONTHEMES 0224 0225 d->iconTextLabel->hide(); 0226 d->iconButton->hide(); 0227 d->resetIconButton->hide(); 0228 0229 #endif 0230 0231 // -------------------------------------------------------- 0232 0233 d->urlsLabel = new QLabel(page); 0234 d->urlsLabel->setText(i18nc("@label: favorites item file properties", "&Items:")); 0235 0236 d->nbImagesLabel = new QLabel(page); 0237 QFont fnt; 0238 fnt.setItalic(true); 0239 d->nbImagesLabel->setFont(fnt); 0240 0241 d->urlsEdit = new DItemsList(page); 0242 d->urlsEdit->setIsLessThanHandler(itemIsLessThanHandler); 0243 d->urlsEdit->setIconSize(d->list->iconSize().width()); 0244 d->urlsEdit->setAllowRAW(true); 0245 d->urlsEdit->setAllowDuplicate(false); 0246 d->urlsEdit->setControlButtonsPlacement(DItemsList::ControlButtonsBelow); 0247 d->urlsEdit->setControlButtons(DItemsList::Add | DItemsList::Remove | DItemsList::Clear); 0248 d->urlsEdit->listView()->setColumn(DItemsListView::Filename, i18nc("@title:column file name", "Name"), true); 0249 d->urlsEdit->listView()->setColumn(DItemsListView::User1, i18nc("@title:column file size", "Size"), true); 0250 d->urlsEdit->listView()->setColumn(DItemsListView::User2, i18nc("@title:column file type-mime", "Type"), true); 0251 d->urlsEdit->listView()->setColumn(DItemsListView::User3, i18nc("@title:column file date", "Date"), true); 0252 d->urlsEdit->listView()->setColumn(DItemsListView::User4, i18nc("@title:column file path", "Path"), true); 0253 0254 d->urlsEdit->setWhatsThis(i18nc("@info", "This is the list of files hosted by this favorite item. " 0255 "The current selected file from this list will be automatically " 0256 "shown in editor when favorite is open. If none is selected, " 0257 "first one from the list will be displayed.")); 0258 d->urlsLabel->setBuddy(d->urlsEdit); 0259 0260 // -------------------------------------------------------- 0261 0262 d->helpLabel = new DAdjustableLabel(page); 0263 QPalette pal = d->helpLabel->palette(); 0264 pal.setColor(QPalette::WindowText, Qt::red); 0265 d->helpLabel->setPalette(pal); 0266 0267 // -------------------------------------------------------- 0268 0269 grid->addWidget(nameLabel, 0, 0, 1, 1); 0270 grid->addWidget(d->nameEdit, 0, 1, 1, 4); 0271 grid->addWidget(hierLabel, 1, 0, 1, 1); 0272 grid->addWidget(d->hierarchyLabel, 1, 1, 1, 4); 0273 grid->addWidget(typeLabel, 2, 0, 1, 1); 0274 grid->addWidget(d->favoriteTypeBox, 2, 1, 1, 4); 0275 grid->addWidget(d->descLabel, 3, 0, 1, 1); 0276 grid->addWidget(d->descEdit, 3, 1, 1, 4); 0277 grid->addWidget(d->dateLabel, 4, 0, 1, 1); 0278 grid->addWidget(d->dateEdit, 4, 1, 1, 3); 0279 grid->addWidget(buttonRow, 4, 3, 1, 1); 0280 grid->addWidget(d->iconTextLabel, 5, 0, 1, 1); 0281 grid->addWidget(d->iconButton, 5, 1, 1, 1); 0282 grid->addWidget(d->resetIconButton, 5, 2, 1, 1); 0283 grid->addWidget(d->urlsEdit, 6, 1, 4, 4); 0284 grid->addWidget(d->urlsLabel, 7, 0, 1, 1); 0285 grid->addWidget(d->nbImagesLabel, 8, 0, 1, 1); 0286 grid->addWidget(d->helpLabel, 10, 0, 1, 5); 0287 grid->setRowStretch(9, 10); 0288 grid->setColumnStretch(4, 10); 0289 0290 QVBoxLayout* const vbx = new QVBoxLayout(this); 0291 vbx->addWidget(page); 0292 vbx->addWidget(d->buttons); 0293 setLayout(vbx); 0294 0295 // -------------------------------------------------------- 0296 0297 connect(d->nameEdit, SIGNAL(textChanged()), 0298 this, SLOT(slotModified())); 0299 0300 connect(d->descEdit, SIGNAL(textChanged()), 0301 this, SLOT(slotModified())); 0302 0303 connect(d->favoriteTypeBox, SIGNAL(activated(int)), 0304 this, SLOT(slotTypeActivated())); 0305 0306 connect(d->urlsEdit, SIGNAL(signalImageListChanged()), 0307 this, SLOT(slotModified())); 0308 0309 connect(d->iconButton, SIGNAL(clicked()), 0310 this, SLOT(slotIconChanged())); 0311 0312 connect(d->resetIconButton, SIGNAL(clicked()), 0313 this, SLOT(slotIconResetClicked())); 0314 0315 connect(d->urlsEdit, SIGNAL(signalImageListChanged()), 0316 this, SLOT(slotUpdateMetadata())); 0317 0318 connect(d->buttons->button(QDialogButtonBox::Ok), SIGNAL(clicked()), 0319 this, SLOT(accept())); 0320 0321 connect(d->buttons->button(QDialogButtonBox::Cancel), SIGNAL(clicked()), 0322 this, SLOT(reject())); 0323 0324 connect(d->buttons->button(QDialogButtonBox::Help), SIGNAL(clicked()), 0325 this, SLOT(slotHelp())); 0326 0327 connect(d->dateLowButton, SIGNAL(clicked()), 0328 this, SLOT(slotDateLowButtonClicked())); 0329 0330 connect(d->dateAvgButton, SIGNAL(clicked()), 0331 this, SLOT(slotDateAverageButtonClicked())); 0332 0333 connect(d->dateHighButton, SIGNAL(clicked()), 0334 this, SLOT(slotDateHighButtonClicked())); 0335 0336 // -------------------------------------------------------- 0337 0338 d->nameEdit->setFocus(); 0339 0340 KConfigGroup group = KSharedConfig::openConfig()->group(objectName()); 0341 winId(); 0342 adjustSize(); 0343 DXmlGuiWindow::restoreWindowSize(windowHandle(), group); 0344 resize(windowHandle()->size()); 0345 } 0346 0347 ShowfotoStackViewFavoriteItemDlg::~ShowfotoStackViewFavoriteItemDlg() 0348 { 0349 KConfigGroup group = KSharedConfig::openConfig()->group(objectName()); 0350 DXmlGuiWindow::saveWindowSize(windowHandle(), group); 0351 0352 delete d; 0353 } 0354 0355 bool ShowfotoStackViewFavoriteItemDlg::canAccept() const 0356 { 0357 if (favoriteType() == ShowfotoStackViewFavoriteItem::FavoriteItem) 0358 { 0359 bool b1 = name().isEmpty(); 0360 bool b2 = urls().isEmpty(); 0361 bool b3 = false; // If dialog in edit mode, the original name can be accepted. 0362 0363 if (d->create || (name() != d->originalName)) 0364 { 0365 b3 = d->list->findFavoriteByHierarchy(ShowfotoStackViewFavoriteItem::hierarchyFromParent(name(), d->pitem)); 0366 } 0367 0368 bool b4 = (!b1 && !b2 && !b3); 0369 0370 if (b4) 0371 { 0372 d->helpLabel->setAdjustedText(QString()); 0373 } 0374 else 0375 { 0376 if (b1) 0377 { 0378 d->helpLabel->setAdjustedText(i18nc("@label", "Note: favorite item name cannot be empty!")); 0379 } 0380 else if (b2) 0381 { 0382 d->helpLabel->setAdjustedText(i18nc("@label", "Note: favorite item files list cannot be empty!")); 0383 } 0384 else if (b3) 0385 { 0386 d->helpLabel->setAdjustedText(i18nc("@label", "Note: favorite item name already exists in hierarchy!")); 0387 } 0388 } 0389 0390 return ( 0391 !b1 && 0392 !b2 && 0393 !b3 0394 ); 0395 } 0396 else 0397 { 0398 bool b1 = name().isEmpty(); 0399 bool b3 = false; // If dialog in edit mode, the original name can be accepted. 0400 0401 if (d->create || (name() != d->originalName)) 0402 { 0403 b3 = d->list->findFavoriteByHierarchy(ShowfotoStackViewFavoriteItem::hierarchyFromParent(name(), d->pitem)); 0404 } 0405 0406 bool b4 = (!b1 && !b3); 0407 0408 if (b4) 0409 { 0410 d->helpLabel->setAdjustedText(QString()); 0411 } 0412 else 0413 { 0414 if (b1) 0415 { 0416 d->helpLabel->setAdjustedText(i18nc("@label", "Note: favorite folder name cannot be empty!")); 0417 } 0418 else if (b3) 0419 { 0420 d->helpLabel->setAdjustedText(i18nc("@label", "Note: favorite folder name already exists in hierarchy!")); 0421 } 0422 } 0423 0424 return ( 0425 !b1 && 0426 !b3 0427 ); 0428 } 0429 } 0430 0431 void ShowfotoStackViewFavoriteItemDlg::slotModified() 0432 { 0433 d->buttons->button(QDialogButtonBox::Ok)->setEnabled(canAccept()); 0434 d->hierarchyLabel->setAdjustedText(ShowfotoStackViewFavoriteItem::hierarchyFromParent(name(), d->pitem)); 0435 int numberOfImages = d->urlsEdit->imageUrls().count(); 0436 d->nbImagesLabel->setText(i18ncp("@info", "%1 file", "%1 files", numberOfImages)); 0437 d->dateLowButton->setEnabled(numberOfImages > 0); 0438 d->dateAvgButton->setEnabled(numberOfImages > 0); 0439 d->dateHighButton->setEnabled(numberOfImages > 0); 0440 } 0441 0442 QString ShowfotoStackViewFavoriteItemDlg::name() const 0443 { 0444 return d->nameEdit->text(); 0445 } 0446 0447 int ShowfotoStackViewFavoriteItemDlg::favoriteType() const 0448 { 0449 return d->favoriteTypeBox->currentIndex(); 0450 } 0451 0452 QString ShowfotoStackViewFavoriteItemDlg::description() const 0453 { 0454 return d->descEdit->text(); 0455 } 0456 0457 QDate ShowfotoStackViewFavoriteItemDlg::date() const 0458 { 0459 return d->dateEdit->date(); 0460 } 0461 0462 QString ShowfotoStackViewFavoriteItemDlg::icon() const 0463 { 0464 return d->icon; 0465 } 0466 0467 QList<QUrl> ShowfotoStackViewFavoriteItemDlg::urls() const 0468 { 0469 return d->urlsEdit->imageUrls(); 0470 } 0471 0472 QUrl ShowfotoStackViewFavoriteItemDlg::currentUrl() const 0473 { 0474 return d->urlsEdit->getCurrentUrl(); 0475 } 0476 0477 void ShowfotoStackViewFavoriteItemDlg::setName(const QString& name) 0478 { 0479 d->nameEdit->setText(name); 0480 d->originalName = name; 0481 } 0482 0483 void ShowfotoStackViewFavoriteItemDlg::setFavoriteType(int favoriteType) 0484 { 0485 d->favoriteTypeBox->setCurrentIndex(favoriteType); 0486 slotTypeActivated(); 0487 } 0488 0489 void ShowfotoStackViewFavoriteItemDlg::setDescription(const QString& desc) 0490 { 0491 d->descEdit->setText(desc); 0492 } 0493 0494 void ShowfotoStackViewFavoriteItemDlg::setDate(const QDate& date) 0495 { 0496 d->dateEdit->setDate(date); 0497 } 0498 0499 void ShowfotoStackViewFavoriteItemDlg::setIcon(const QString& icon) 0500 { 0501 d->icon = icon; 0502 } 0503 0504 void ShowfotoStackViewFavoriteItemDlg::setUrls(const QList<QUrl>& urls) 0505 { 0506 d->urlsEdit->slotAddImages(urls); 0507 } 0508 0509 void ShowfotoStackViewFavoriteItemDlg::setCurrentUrl(const QUrl& url) 0510 { 0511 d->urlsEdit->setCurrentUrl(url); 0512 } 0513 0514 void ShowfotoStackViewFavoriteItemDlg::setIconSize(int size) 0515 { 0516 d->urlsEdit->setIconSize(size); 0517 } 0518 0519 void ShowfotoStackViewFavoriteItemDlg::setSortOrder(int order) 0520 { 0521 s_sortOrder = (Qt::SortOrder)order; 0522 d->urlsEdit->listView()->sortItems(s_sortRole + DItemsListView::Filename, s_sortOrder); 0523 } 0524 0525 void ShowfotoStackViewFavoriteItemDlg::setSortRole(int role) 0526 { 0527 s_sortRole = (ShowfotoStackViewList::StackViewRole)role; 0528 d->urlsEdit->listView()->sortItems(s_sortRole + DItemsListView::Filename, s_sortOrder); 0529 } 0530 0531 void ShowfotoStackViewFavoriteItemDlg::setParentItem(ShowfotoStackViewFavoriteItem* const pitem) 0532 { 0533 d->pitem = pitem; 0534 } 0535 0536 void ShowfotoStackViewFavoriteItemDlg::slotIconResetClicked() 0537 { 0538 d->icon = QLatin1String("folder-favorites"); 0539 d->iconButton->setIcon(QIcon::fromTheme(d->icon)); 0540 } 0541 0542 void ShowfotoStackViewFavoriteItemDlg::slotIconChanged() 0543 { 0544 0545 #ifdef HAVE_KICONTHEMES 0546 0547 QPointer<KIconDialog> dlg = new KIconDialog(this); 0548 dlg->setup(KIconLoader::NoGroup, KIconLoader::Application, false, 20, false, false, false); 0549 QString icon = dlg->openDialog(); 0550 delete dlg; 0551 0552 if (icon.isEmpty() || (icon == d->icon)) 0553 { 0554 return; 0555 } 0556 0557 d->icon = icon; 0558 d->iconButton->setIcon(QIcon::fromTheme(d->icon)); 0559 0560 #endif 0561 0562 } 0563 0564 QList<QDate> ShowfotoStackViewFavoriteItemDlg::getItemDates() const 0565 { 0566 QList<QDate> dates; 0567 QDateTime dt; 0568 QTreeWidgetItemIterator it(d->urlsEdit->listView()); 0569 0570 while (*it) 0571 { 0572 dt = (*it)->data(DItemsListView::User3, Qt::UserRole).toDateTime(); 0573 0574 if (dt.isValid()) 0575 { 0576 dates << dt.date(); 0577 } 0578 0579 ++it; 0580 } 0581 0582 return dates; 0583 } 0584 0585 void ShowfotoStackViewFavoriteItemDlg::slotUpdateMetadata() 0586 { 0587 QTreeWidgetItemIterator it(d->urlsEdit->listView()); 0588 0589 while (*it) 0590 { 0591 DItemsListViewItem* const lvItem = dynamic_cast<DItemsListViewItem*>(*it); 0592 0593 if (lvItem) 0594 { 0595 QFileInfo inf(lvItem->url().toLocalFile()); 0596 ShowfotoItemInfo iteminf = ShowfotoItemInfo::itemInfoFromFile(inf); 0597 0598 QString localeFileSize = QLocale().toString(iteminf.size); 0599 QString str = ItemPropertiesTab::humanReadableBytesCount(iteminf.size); 0600 lvItem->setText(DItemsListView::User1, str); 0601 lvItem->setData(DItemsListView::User1, Qt::UserRole, iteminf.size); 0602 0603 QFileInfo fileInfo(iteminf.name); 0604 QString rawFilesExt = DRawDecoder::rawFiles(); 0605 QString ext = fileInfo.suffix().toUpper(); 0606 0607 if (!ext.isEmpty() && rawFilesExt.toUpper().contains(ext)) 0608 { 0609 lvItem->setText(DItemsListView::User2, i18nc("@info: item properties", "RAW Image")); 0610 } 0611 else 0612 { 0613 lvItem->setText(DItemsListView::User2, QMimeDatabase().mimeTypeForFile(fileInfo).comment()); 0614 } 0615 0616 QDateTime dt = (iteminf.ctime.isValid() ? iteminf.ctime : iteminf.dtime); 0617 str = QLocale().toString(dt, QLocale::ShortFormat); 0618 lvItem->setText(DItemsListView::User3, str); 0619 lvItem->setData(DItemsListView::User3, Qt::UserRole, dt); 0620 0621 lvItem->setText(DItemsListView::User4, inf.absolutePath()); 0622 } 0623 0624 ++it; 0625 } 0626 } 0627 0628 bool ShowfotoStackViewFavoriteItemDlg::favoriteItemDialog(ShowfotoStackViewFavoriteList* const list, 0629 QString& name, 0630 int& favoriteType, 0631 QString& desc, 0632 QDate& date, 0633 QString& icon, 0634 QList<QUrl>& urls, 0635 QUrl& current, 0636 int iconSize, 0637 int sortOrder, 0638 int sortRole, 0639 ShowfotoStackViewFavoriteItem* const pitem, 0640 bool create) 0641 { 0642 QPointer<ShowfotoStackViewFavoriteItemDlg> dlg = new ShowfotoStackViewFavoriteItemDlg(list, create); 0643 dlg->setParentItem(pitem); 0644 dlg->setName(name); 0645 dlg->setDescription(desc); 0646 dlg->setDate(date); 0647 dlg->setIcon(icon); 0648 dlg->setUrls(urls); 0649 dlg->setCurrentUrl(current); 0650 dlg->setIconSize(iconSize); 0651 dlg->setSortOrder(sortOrder); 0652 dlg->setSortRole(sortRole); 0653 dlg->setFavoriteType(favoriteType); 0654 0655 bool valRet = dlg->exec(); 0656 0657 if (valRet == QDialog::Accepted) 0658 { 0659 name = dlg->name(); 0660 desc = dlg->description(); 0661 date = dlg->date(); 0662 icon = dlg->icon(); 0663 urls = dlg->urls(); 0664 current = dlg->currentUrl(); 0665 favoriteType = dlg->favoriteType(); 0666 } 0667 0668 delete dlg; 0669 0670 return valRet; 0671 } 0672 0673 void ShowfotoStackViewFavoriteItemDlg::slotTypeActivated() 0674 { 0675 bool b = (favoriteType() == ShowfotoStackViewFavoriteItem::FavoriteItem); 0676 0677 d->descLabel->setEnabled(b); 0678 d->descEdit->setEnabled(b); 0679 d->dateLabel->setEnabled(b); 0680 d->dateEdit->setEnabled(b); 0681 d->iconTextLabel->setEnabled(b); 0682 d->iconButton->setEnabled(b); 0683 d->resetIconButton->setEnabled(b); 0684 d->urlsEdit->setEnabled(b); 0685 d->urlsLabel->setEnabled(b); 0686 d->nbImagesLabel->setEnabled(b); 0687 d->dateLowButton->setEnabled(b); 0688 d->dateAvgButton->setEnabled(b); 0689 d->dateHighButton->setEnabled(b); 0690 0691 if (b) 0692 { 0693 if (d->create) 0694 { 0695 setWindowTitle(i18nc("@title:window", "New Favorite Item")); 0696 } 0697 else 0698 { 0699 setWindowTitle(i18nc("@title:window", "Edit Favorite Item")); 0700 } 0701 } 0702 else 0703 { 0704 if (d->create) 0705 { 0706 setWindowTitle(i18nc("@title:window", "New Favorite Folder")); 0707 } 0708 else 0709 { 0710 setWindowTitle(i18nc("@title:window", "Edit Favorite Folder")); 0711 } 0712 } 0713 0714 slotModified(); 0715 } 0716 0717 void ShowfotoStackViewFavoriteItemDlg::slotDateLowButtonClicked() 0718 { 0719 setCursor(Qt::WaitCursor); 0720 0721 QDate lowDate = getItemDates().first(); 0722 0723 if (lowDate.isValid()) 0724 { 0725 d->dateEdit->setDate(lowDate); 0726 } 0727 0728 setCursor(Qt::ArrowCursor); 0729 } 0730 0731 void ShowfotoStackViewFavoriteItemDlg::slotDateHighButtonClicked() 0732 { 0733 setCursor(Qt::WaitCursor); 0734 0735 QDate highDate = getItemDates().last(); 0736 0737 if (highDate.isValid()) 0738 { 0739 d->dateEdit->setDate(highDate); 0740 } 0741 0742 setCursor(Qt::ArrowCursor); 0743 } 0744 0745 void ShowfotoStackViewFavoriteItemDlg::slotDateAverageButtonClicked() 0746 { 0747 setCursor(Qt::WaitCursor); 0748 0749 QList<QDate> dates = getItemDates(); 0750 qint64 julianDays = 0; 0751 0752 Q_FOREACH (const QDate& date, dates) 0753 { 0754 julianDays += date.toJulianDay(); 0755 } 0756 0757 QDate avDate = QDate::fromJulianDay(julianDays / dates.size()); 0758 0759 setCursor(Qt::ArrowCursor); 0760 0761 if (avDate.isValid()) 0762 { 0763 d->dateEdit->setDate(avDate); 0764 } 0765 else 0766 { 0767 QMessageBox::critical(this, i18nc("@title:window, favorite item properties", "Could not Calculate Average"), 0768 i18nc("@info: favorite item properties", "Could not calculate date average for this favorite item.")); 0769 } 0770 } 0771 0772 bool ShowfotoStackViewFavoriteItemDlg::itemIsLessThanHandler(const QTreeWidgetItem* current, const QTreeWidgetItem& other) 0773 { 0774 int result = 0; 0775 0776 switch (s_sortRole + DItemsListView::Filename) 0777 { 0778 case DItemsListView::User1: // Size 0779 { 0780 result = (ShowfotoItemSortSettings::compareByOrder(current->data(DItemsListView::User1, Qt::UserRole).toInt(), 0781 other.data(DItemsListView::User1, Qt::UserRole).toInt(), 0782 s_sortOrder)); 0783 break; 0784 } 0785 0786 case DItemsListView::User2: // Mime-type 0787 { 0788 result = (ShowfotoItemSortSettings::naturalCompare(current->text(DItemsListView::User2), 0789 other.text(DItemsListView::User2), 0790 s_sortOrder, 0791 Qt::CaseSensitive)); 0792 break; 0793 } 0794 0795 case DItemsListView::User3: // Date 0796 { 0797 result = (ShowfotoItemSortSettings::compareByOrder(current->data(DItemsListView::User3, Qt::UserRole).toDateTime(), 0798 other.data(DItemsListView::User3, Qt::UserRole).toDateTime(), 0799 s_sortOrder)); 0800 break; 0801 } 0802 0803 default: // Name 0804 { 0805 result = (ShowfotoItemSortSettings::naturalCompare(current->text(DItemsListView::Filename), 0806 other.text(DItemsListView::Filename), 0807 s_sortOrder, 0808 Qt::CaseSensitive)); 0809 break; 0810 } 0811 } 0812 0813 return (result < 0); 0814 } 0815 0816 void ShowfotoStackViewFavoriteItemDlg::slotHelp() 0817 { 0818 Digikam::openOnlineDocumentation(QLatin1String("showfoto_editor"), 0819 QLatin1String("showfoto_leftsidebar"), 0820 QLatin1String("showfoto-stacktab")); 0821 } 0822 0823 } // namespace ShowFoto 0824 0825 #include "moc_showfotostackviewfavoriteitemdlg.cpp"