File indexing completed on 2025-01-19 03:57:32
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 favorites 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 "showfotostackviewfavorites.h" 0016 0017 // Qt includes 0018 0019 #include <QDir> 0020 #include <QStandardPaths> 0021 #include <QGridLayout> 0022 #include <QLabel> 0023 #include <QToolButton> 0024 #include <QVBoxLayout> 0025 #include <QApplication> 0026 #include <QIcon> 0027 #include <QMessageBox> 0028 #include <QFile> 0029 #include <QDate> 0030 #include <QDomDocument> 0031 #include <QDomElement> 0032 #include <QTextStream> 0033 #if (QT_VERSION < QT_VERSION_CHECK(6, 0, 0)) 0034 #include <QTextCodec> 0035 #endif 0036 0037 // KDE includes 0038 0039 #include <klocalizedstring.h> 0040 0041 // Local includes 0042 0043 #include "digikam_debug.h" 0044 #include "thumbnailsize.h" 0045 #include "showfotostackviewsidebar.h" 0046 #include "showfotostackviewfavoriteitemdlg.h" 0047 #include "showfotostackviewfavoritelist.h" 0048 #include "showfotostackviewfavoriteitem.h" 0049 0050 namespace ShowFoto 0051 { 0052 0053 class Q_DECL_HIDDEN ShowfotoStackViewFavorites::Private 0054 { 0055 public: 0056 0057 explicit Private() 0058 : addBtn (nullptr), 0059 fldBtn (nullptr), 0060 delBtn (nullptr), 0061 edtBtn (nullptr), 0062 favoritesList (nullptr), 0063 topFavorites (nullptr), 0064 sidebar (nullptr), 0065 favoritesFilter(nullptr) 0066 { 0067 file = QStandardPaths::writableLocation(QStandardPaths::AppDataLocation) + QLatin1String("/favorites.xml"); 0068 } 0069 0070 public: 0071 0072 QList<QAction*> actionsList; ///< Used to shared actions with list-view context menu. 0073 QToolButton* addBtn; ///< Add favorite button. 0074 QToolButton* fldBtn; ///< Add sub-folder button. 0075 QToolButton* delBtn; ///< Delete item button. 0076 QToolButton* edtBtn; ///< Edit item button. 0077 ShowfotoStackViewFavoriteList* favoritesList; 0078 ShowfotoStackViewFavoriteItem* topFavorites; ///< Top-level parent of all favorite items. 0079 ShowfotoStackViewSideBar* sidebar; 0080 QString file; ///< Path to store favorites XML data file. 0081 SearchTextBar* favoritesFilter; 0082 }; 0083 0084 ShowfotoStackViewFavorites::ShowfotoStackViewFavorites(ShowfotoStackViewSideBar* const sidebar) 0085 : QWidget(sidebar), 0086 d (new Private) 0087 { 0088 d->sidebar = sidebar; 0089 QGridLayout* const grid = new QGridLayout(this); 0090 0091 QLabel* const title = new QLabel(this); 0092 title->setText(i18nc("@title", "Favorites")); 0093 0094 // -------------------------------------------------------- 0095 0096 QAction* btnAction = nullptr; 0097 0098 btnAction = new QAction(this); 0099 btnAction->setObjectName(QLatin1String("AddFavorite")); 0100 btnAction->setIcon(QIcon::fromTheme(QLatin1String("list-add"))); 0101 btnAction->setText(i18nc("@action", "Add Favorite")); 0102 btnAction->setToolTip(i18nc("@info", "Add new bookmark to the list")); 0103 0104 connect(btnAction, SIGNAL(triggered(bool)), 0105 this, SLOT(slotAddFavorite())); 0106 0107 d->actionsList << btnAction; 0108 0109 d->addBtn = new QToolButton(this); 0110 d->addBtn->setDefaultAction(btnAction); 0111 d->addBtn->setFocusPolicy(Qt::NoFocus); 0112 d->addBtn->setEnabled(true); 0113 0114 // --- 0115 0116 btnAction = new QAction(this); 0117 btnAction->setObjectName(QLatin1String("AddFolder")); 0118 btnAction->setIcon(QIcon::fromTheme(QLatin1String("folder-new"))); 0119 btnAction->setText(i18nc("@action", "Add Sub-Folder")); 0120 btnAction->setToolTip(i18nc("@info", "Add new sub-folder to the list")); 0121 0122 connect(btnAction, SIGNAL(triggered(bool)), 0123 this, SLOT(slotAddSubFolder())); 0124 0125 d->actionsList << btnAction; 0126 0127 d->fldBtn = new QToolButton(this); 0128 d->fldBtn->setDefaultAction(btnAction); 0129 d->fldBtn->setFocusPolicy(Qt::NoFocus); 0130 d->fldBtn->setEnabled(true); 0131 0132 // --- 0133 0134 btnAction = new QAction(this); 0135 btnAction->setObjectName(QLatin1String("DelItem")); 0136 btnAction->setIcon(QIcon::fromTheme(QLatin1String("list-remove"))); 0137 btnAction->setText(i18nc("@action", "Delete Item")); 0138 btnAction->setToolTip(i18nc("@info", "Remove selected item from the list")); 0139 0140 connect(btnAction, SIGNAL(triggered(bool)), 0141 this, SLOT(slotDelItem())); 0142 0143 d->actionsList << btnAction; 0144 0145 d->delBtn = new QToolButton(this); 0146 d->delBtn->setDefaultAction(btnAction); 0147 d->delBtn->setFocusPolicy(Qt::NoFocus); 0148 d->delBtn->setEnabled(false); 0149 0150 // --- 0151 0152 btnAction = new QAction(this); 0153 btnAction->setObjectName(QLatin1String("EditItem")); 0154 btnAction->setIcon(QIcon::fromTheme(QLatin1String("document-edit"))); 0155 btnAction->setText(i18nc("@action", "Edit Item")); 0156 btnAction->setToolTip(i18nc("@info", "Edit current item from the list")); 0157 0158 connect(btnAction, SIGNAL(triggered(bool)), 0159 this, SLOT(slotEditItem())); 0160 0161 d->actionsList << btnAction; 0162 0163 d->edtBtn = new QToolButton(this); 0164 d->edtBtn->setDefaultAction(btnAction); 0165 d->edtBtn->setFocusPolicy(Qt::NoFocus); 0166 d->edtBtn->setEnabled(false); 0167 0168 // --- 0169 0170 d->favoritesList = new ShowfotoStackViewFavoriteList(this); 0171 d->favoritesFilter = new SearchTextBar(this, 0172 QLatin1String("FavoritesSearchBar"), 0173 i18nc("@info: search text bar", "Search in Favorites...") 0174 ); 0175 0176 grid->setAlignment(Qt::AlignTop); 0177 grid->addWidget(title, 0, 0, 1, 1); 0178 grid->addWidget(d->addBtn, 0, 2, 1, 1); 0179 grid->addWidget(d->fldBtn, 0, 3, 1, 1); 0180 grid->addWidget(d->delBtn, 0, 4, 1, 1); 0181 grid->addWidget(d->edtBtn, 0, 5, 1, 1); 0182 grid->addWidget(d->favoritesList, 1, 0, 1, 6); 0183 grid->addWidget(d->favoritesFilter, 2, 0, 1, 6); 0184 0185 grid->setRowStretch(1, 10); 0186 grid->setColumnStretch(1, 10); 0187 grid->setContentsMargins(QMargins()); 0188 0189 // -------------------------------------------------------- 0190 0191 connect(d->favoritesList, SIGNAL(itemSelectionChanged()), 0192 this, SLOT(slotItemSelectionChanged())); 0193 0194 connect(d->favoritesList, SIGNAL(itemDoubleClicked(QTreeWidgetItem*,int)), 0195 this, SLOT(slotFavoriteDoubleClicked(QTreeWidgetItem*))); 0196 0197 connect(d->sidebar, SIGNAL(signalAddFavorite()), 0198 this, SLOT(slotAddFavorite())); 0199 0200 connect(d->favoritesList, SIGNAL(signalAddFavorite()), 0201 this, SLOT(slotAddFavorite())); 0202 0203 connect(d->favoritesList, SIGNAL(signalAddFavorite(QList<QUrl>,QUrl)), 0204 this, SLOT(slotAddFavorite(QList<QUrl>,QUrl))); 0205 0206 connect(d->favoritesList, SIGNAL(signalLoadContentsFromFiles(QStringList,QString)), 0207 this, SIGNAL(signalLoadContentsFromFiles(QStringList,QString))); 0208 0209 connect(d->favoritesFilter, SIGNAL(signalSearchTextSettings(SearchTextSettings)), 0210 this, SLOT(slotSearchTextChanged(SearchTextSettings))); 0211 0212 connect(d->favoritesList, SIGNAL(signalSearchResult(int)), 0213 this, SLOT(slotSearchResult(int))); 0214 } 0215 0216 ShowfotoStackViewFavorites::~ShowfotoStackViewFavorites() 0217 { 0218 delete d; 0219 } 0220 0221 QAction* ShowfotoStackViewFavorites::toolBarAction(const QString& name) const 0222 { 0223 Q_FOREACH (QAction* const act, d->actionsList) 0224 { 0225 if (act && (act->objectName() == name)) 0226 { 0227 return act; 0228 } 0229 } 0230 0231 return nullptr; 0232 } 0233 0234 QTreeWidgetItem* ShowfotoStackViewFavorites::topFavoritesItem() const 0235 { 0236 return d->topFavorites; 0237 } 0238 0239 void ShowfotoStackViewFavorites::loadContents() 0240 { 0241 d->favoritesList->slotLoadContents(); 0242 } 0243 0244 void ShowfotoStackViewFavorites::slotAddFavorite() 0245 { 0246 slotAddFavorite(d->sidebar->urls(), d->sidebar->currentUrl()); 0247 } 0248 0249 void ShowfotoStackViewFavorites::slotAddSubFolder() 0250 { 0251 0252 QString name; 0253 QString desc; 0254 QDate date; 0255 QString icon; 0256 QList<QUrl> urls; 0257 QUrl currentUrl; 0258 int favType = ShowfotoStackViewFavoriteItem::FavoriteFolder; 0259 ShowfotoStackViewFavoriteItem* const parent = d->favoritesList->currentItem() ? dynamic_cast<ShowfotoStackViewFavoriteItem*>(d->favoritesList->currentItem()) 0260 : d->topFavorites; 0261 bool ok = ShowfotoStackViewFavoriteItemDlg::favoriteItemDialog(d->favoritesList, 0262 name, 0263 favType, 0264 desc, 0265 date, 0266 icon, 0267 urls, 0268 currentUrl, 0269 d->sidebar->iconSize(), 0270 d->sidebar->sortOrder(), 0271 d->sidebar->sortRole(), 0272 parent, 0273 true 0274 ); 0275 0276 if (ok) 0277 { 0278 if (favType == ShowfotoStackViewFavoriteItem::FavoriteItem) 0279 { 0280 ShowfotoStackViewFavoriteItem* const item = new ShowfotoStackViewFavoriteItem(parent, 0281 ShowfotoStackViewFavoriteItem::FavoriteItem); 0282 item->setName(name); 0283 item->setDescription(desc); 0284 item->setDate(date); 0285 item->setIcon(0, QIcon::fromTheme(icon)); 0286 item->setUrls(urls); 0287 item->setCurrentUrl(currentUrl); 0288 } 0289 else 0290 { 0291 ShowfotoStackViewFavoriteItem* const folder = new ShowfotoStackViewFavoriteItem(parent, 0292 ShowfotoStackViewFavoriteItem::FavoriteFolder); 0293 folder->setName(name); 0294 } 0295 0296 parent->setExpanded(true); 0297 } 0298 } 0299 0300 void ShowfotoStackViewFavorites::slotAddFavorite(const QList<QUrl>& newUrls, const QUrl& current) 0301 { 0302 QString name; 0303 QString desc; 0304 int favType = ShowfotoStackViewFavoriteItem::FavoriteItem; 0305 QDate date = QDate::currentDate(); 0306 QString icon = QLatin1String("folder-favorites"); 0307 QList<QUrl> urls = newUrls; 0308 QUrl currentUrl = current; 0309 ShowfotoStackViewFavoriteItem* const parent = d->favoritesList->currentItem() ? dynamic_cast<ShowfotoStackViewFavoriteItem*>(d->favoritesList->currentItem()) 0310 : d->topFavorites; 0311 bool ok = ShowfotoStackViewFavoriteItemDlg::favoriteItemDialog(d->favoritesList, 0312 name, 0313 favType, 0314 desc, 0315 date, 0316 icon, 0317 urls, 0318 currentUrl, 0319 d->sidebar->iconSize(), 0320 d->sidebar->sortOrder(), 0321 d->sidebar->sortRole(), 0322 parent, 0323 true 0324 ); 0325 0326 if (ok) 0327 { 0328 if (favType == ShowfotoStackViewFavoriteItem::FavoriteItem) 0329 { 0330 ShowfotoStackViewFavoriteItem* const item = new ShowfotoStackViewFavoriteItem(parent, 0331 ShowfotoStackViewFavoriteItem::FavoriteItem); 0332 item->setName(name); 0333 item->setDescription(desc); 0334 item->setDate(date); 0335 item->setIcon(0, QIcon::fromTheme(icon)); 0336 item->setUrls(urls); 0337 item->setCurrentUrl(currentUrl); 0338 } 0339 else 0340 { 0341 ShowfotoStackViewFavoriteItem* const folder = new ShowfotoStackViewFavoriteItem(parent, 0342 ShowfotoStackViewFavoriteItem::FavoriteFolder); 0343 folder->setName(name); 0344 } 0345 0346 parent->setExpanded(true); 0347 } 0348 } 0349 0350 void ShowfotoStackViewFavorites::slotDelItem() 0351 { 0352 ShowfotoStackViewFavoriteItem* const fitem = dynamic_cast<ShowfotoStackViewFavoriteItem*>(d->favoritesList->currentItem()); 0353 0354 if (!fitem) 0355 { 0356 return; 0357 } 0358 0359 if (QMessageBox::question(this, i18nc("@title:window", "Confirm Item Deletion"), 0360 i18nc("@info", "Are you sure you want to remove the item \"%1\"\n" 0361 "and all nested items if any?", fitem->name())) 0362 != QMessageBox::Yes) 0363 { 0364 return; 0365 } 0366 0367 d->favoritesList->removeItemWidget(fitem, 0); 0368 delete fitem; 0369 } 0370 0371 void ShowfotoStackViewFavorites::slotEditItem() 0372 { 0373 ShowfotoStackViewFavoriteItem* const item = dynamic_cast<ShowfotoStackViewFavoriteItem*>(d->favoritesList->currentItem()); 0374 0375 if (item && (item->favoriteType() == ShowfotoStackViewFavoriteItem::FavoriteItem)) 0376 { 0377 int favType = item->favoriteType(); 0378 QString name = item->name(); 0379 QString desc = item->description(); 0380 QDate date = item->date(); 0381 QString icon = item->icon(0).name(); 0382 QList<QUrl> urls = item->urls(); 0383 QUrl currentUrl = item->currentUrl(); 0384 ShowfotoStackViewFavoriteItem* const parent = dynamic_cast<ShowfotoStackViewFavoriteItem*>(item->parent()); 0385 bool ok = ShowfotoStackViewFavoriteItemDlg::favoriteItemDialog(d->favoritesList, 0386 name, 0387 favType, 0388 desc, 0389 date, 0390 icon, 0391 urls, 0392 currentUrl, 0393 d->sidebar->iconSize(), 0394 d->sidebar->sortOrder(), 0395 d->sidebar->sortRole(), 0396 parent 0397 ); 0398 0399 if (ok) 0400 { 0401 if (favType == ShowfotoStackViewFavoriteItem::FavoriteItem) 0402 { 0403 item->setName(name); 0404 item->setDescription(desc); 0405 item->setDate(date); 0406 item->setIcon(0, QIcon::fromTheme(icon)); 0407 item->setUrls(urls); 0408 item->setCurrentUrl(currentUrl); 0409 } 0410 else 0411 { 0412 item->setFavoriteType(favType); 0413 item->setName(name); 0414 } 0415 } 0416 0417 return; 0418 } 0419 0420 if (item && (item->favoriteType() == ShowfotoStackViewFavoriteItem::FavoriteFolder)) 0421 { 0422 QString desc; 0423 QDate date; 0424 QString icon; 0425 QList<QUrl> urls; 0426 QUrl currentUrl; 0427 int favType = item->favoriteType(); 0428 QString name = item->name(); 0429 ShowfotoStackViewFavoriteItem* const parent = dynamic_cast<ShowfotoStackViewFavoriteItem*>(item->parent()); 0430 bool ok = ShowfotoStackViewFavoriteItemDlg::favoriteItemDialog(d->favoritesList, 0431 name, 0432 favType, 0433 desc, 0434 date, 0435 icon, 0436 urls, 0437 currentUrl, 0438 d->sidebar->iconSize(), 0439 d->sidebar->sortOrder(), 0440 d->sidebar->sortRole(), 0441 parent 0442 ); 0443 0444 if (ok) 0445 { 0446 if (favType == ShowfotoStackViewFavoriteItem::FavoriteItem) 0447 { 0448 item->setFavoriteType(favType); 0449 item->setName(name); 0450 item->setDescription(desc); 0451 item->setDate(date); 0452 item->setIcon(0, QIcon::fromTheme(icon)); 0453 item->setUrls(urls); 0454 item->setCurrentUrl(currentUrl); 0455 } 0456 else 0457 { 0458 item->setName(name); 0459 } 0460 } 0461 } 0462 } 0463 0464 void ShowfotoStackViewFavorites::slotItemSelectionChanged() 0465 { 0466 bool b = false; 0467 QTreeWidgetItem* const item = d->favoritesList->currentItem(); 0468 0469 if (item) 0470 { 0471 ShowfotoStackViewFavoriteItem* const fitem = dynamic_cast<ShowfotoStackViewFavoriteItem*>(item); 0472 0473 if (fitem && (fitem->favoriteType() != ShowfotoStackViewFavoriteItem::FavoriteRoot)) 0474 { 0475 b = true; 0476 } 0477 } 0478 0479 d->delBtn->setEnabled(b); 0480 d->edtBtn->setEnabled(b); 0481 } 0482 0483 void ShowfotoStackViewFavorites::slotFavoriteDoubleClicked(QTreeWidgetItem* item) 0484 { 0485 ShowfotoStackViewFavoriteItem* const fvitem = dynamic_cast<ShowfotoStackViewFavoriteItem*>(item); 0486 0487 if (fvitem && (fvitem->favoriteType() == ShowfotoStackViewFavoriteItem::FavoriteItem)) 0488 { 0489 Q_EMIT signalLoadContentsFromFiles(fvitem->urlsToPaths(), fvitem->currentUrl().toLocalFile()); 0490 } 0491 } 0492 0493 void ShowfotoStackViewFavorites::slotItemListChanged(int nbitems) 0494 { 0495 d->addBtn->setEnabled(nbitems > 0); 0496 } 0497 0498 bool ShowfotoStackViewFavorites::saveSettings() 0499 { 0500 QDomDocument doc(QLatin1String("favorites")); 0501 doc.setContent(QLatin1String("<!DOCTYPE XMLFavorites><favorites version=\"1.0\" client=\"showfoto\" encoding=\"UTF-8\"/>")); 0502 QDomElement docElem = doc.documentElement(); 0503 0504 // --- 0505 0506 QDomElement elemExpand = doc.createElement(QLatin1String("TopExpanded")); 0507 elemExpand.setAttribute(QLatin1String("value"), d->topFavorites->isExpanded()); 0508 docElem.appendChild(elemExpand); 0509 0510 // --- 0511 0512 QDomElement elemList = doc.createElement(QLatin1String("FavoritesList")); 0513 docElem.appendChild(elemList); 0514 QTreeWidgetItemIterator it2(d->favoritesList); 0515 0516 while (*it2) 0517 { 0518 ShowfotoStackViewFavoriteItem* const item = dynamic_cast<ShowfotoStackViewFavoriteItem*>(*it2); 0519 0520 if (item && (item->favoriteType() != ShowfotoStackViewFavoriteItem::FavoriteRoot)) 0521 { 0522 QDomElement elem = doc.createElement(QLatin1String("Favorite")); 0523 0524 QDomElement type = doc.createElement(QLatin1String("Type")); 0525 type.setAttribute(QLatin1String("value"), item->favoriteType()); 0526 elem.appendChild(type); 0527 0528 QDomElement name = doc.createElement(QLatin1String("Name")); 0529 name.setAttribute(QLatin1String("value"), item->name()); 0530 elem.appendChild(name); 0531 0532 QDomElement desc = doc.createElement(QLatin1String("Description")); 0533 desc.setAttribute(QLatin1String("value"), item->description()); 0534 elem.appendChild(desc); 0535 0536 QDomElement hier = doc.createElement(QLatin1String("Hierarchy")); 0537 hier.setAttribute(QLatin1String("value"), item->hierarchy()); 0538 elem.appendChild(hier); 0539 0540 QDomElement date = doc.createElement(QLatin1String("Date")); 0541 date.setAttribute(QLatin1String("value"), item->date().toString()); 0542 elem.appendChild(date); 0543 0544 QDomElement icon = doc.createElement(QLatin1String("Icon")); 0545 icon.setAttribute(QLatin1String("value"), item->icon(0).name()); 0546 elem.appendChild(icon); 0547 0548 QDomElement iexp = doc.createElement(QLatin1String("IsExpanded")); 0549 iexp.setAttribute(QLatin1String("value"), item->isExpanded()); 0550 elem.appendChild(iexp); 0551 0552 QDomElement urls = doc.createElement(QLatin1String("UrlsList")); 0553 elem.appendChild(urls); 0554 0555 Q_FOREACH (const QUrl& url, item->urls()) 0556 { 0557 QDomElement e = doc.createElement(QLatin1String("Url")); 0558 e.setAttribute(QLatin1String("value"), url.toLocalFile()); 0559 urls.appendChild(e); 0560 } 0561 0562 QDomElement curr = doc.createElement(QLatin1String("CurrentUrl")); 0563 curr.setAttribute(QLatin1String("value"), item->currentUrl().toLocalFile()); 0564 elem.appendChild(curr); 0565 0566 elemList.appendChild(elem); 0567 } 0568 0569 ++it2; 0570 } 0571 0572 QFile file(d->file); 0573 0574 if (!file.open(QIODevice::WriteOnly)) 0575 { 0576 return false; 0577 } 0578 0579 QTextStream stream(&file); 0580 0581 #if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0)) 0582 0583 stream.setEncoding(QStringConverter::Utf8); 0584 0585 #else 0586 0587 stream.setCodec(QTextCodec::codecForName("UTF-8")); 0588 0589 #endif 0590 0591 stream.setAutoDetectUnicode(true); 0592 stream << doc.toString(); 0593 file.close(); 0594 0595 return true; 0596 } 0597 0598 bool ShowfotoStackViewFavorites::readSettings() 0599 { 0600 d->favoritesList->clear(); 0601 0602 d->topFavorites = new ShowfotoStackViewFavoriteItem(d->favoritesList);; 0603 0604 QFile file(d->file); 0605 0606 if (!file.open(QIODevice::ReadOnly)) 0607 { 0608 return false; 0609 } 0610 0611 QDomDocument doc(QLatin1String("favorites")); 0612 0613 if (!doc.setContent(&file)) 0614 { 0615 return false; 0616 } 0617 0618 QDomElement docElem = doc.documentElement(); 0619 0620 if (docElem.tagName() != QLatin1String("favorites")) 0621 { 0622 return false; 0623 } 0624 0625 for (QDomNode n1 = docElem.firstChild() ; !n1.isNull() ; n1 = n1.nextSibling()) 0626 { 0627 QDomElement e1 = n1.toElement(); 0628 0629 if (e1.isNull()) 0630 { 0631 continue; 0632 } 0633 0634 if (e1.tagName() == QLatin1String("TopExpanded")) 0635 { 0636 d->topFavorites->setExpanded((bool)e1.attribute(QLatin1String("value")).toUInt()); 0637 continue; 0638 } 0639 0640 // --- 0641 0642 if (e1.tagName() == QLatin1String("FavoritesList")) 0643 { 0644 int unamedID = 1; 0645 0646 for (QDomNode n2 = e1.firstChild() ; !n2.isNull() ; n2 = n2.nextSibling()) 0647 { 0648 QDomElement e2 = n2.toElement(); 0649 0650 if (e2.tagName() == QLatin1String("Favorite")) 0651 { 0652 bool isExpanded = true; 0653 int type = ShowfotoStackViewFavoriteItem::FavoriteFolder; 0654 QDate date = QDate::currentDate(); 0655 QString icon = QString::fromLatin1("folder-favorites"); 0656 QString name; 0657 QString desc; 0658 QString hierarchy; 0659 QList<QUrl> urls; 0660 QString curr; 0661 0662 for (QDomNode n3 = e2.firstChild() ; !n3.isNull() ; n3 = n3.nextSibling()) 0663 { 0664 QDomElement e3 = n3.toElement(); 0665 QString name3 = e3.tagName(); 0666 QString val3 = e3.attribute(QLatin1String("value")); 0667 0668 if (name3 == QLatin1String("Name")) 0669 { 0670 if (val3.isEmpty()) 0671 { 0672 val3 = i18nc("@title", "Unnamed") + QString::fromLatin1("_%1").arg(unamedID); 0673 unamedID++; 0674 } 0675 0676 name = val3; 0677 } 0678 else if (name3 == QLatin1String("Type")) 0679 { 0680 type = val3.toInt(); 0681 } 0682 else if (name3 == QLatin1String("Description")) 0683 { 0684 desc = val3; 0685 } 0686 else if (name3 == QLatin1String("Hierarchy")) 0687 { 0688 hierarchy = val3; 0689 } 0690 else if (name3 == QLatin1String("Date")) 0691 { 0692 if (!val3.isEmpty()) 0693 { 0694 date = QDate::fromString(val3); 0695 } 0696 } 0697 else if (name3 == QLatin1String("Icon")) 0698 { 0699 if (!val3.isEmpty()) 0700 { 0701 icon = val3; 0702 } 0703 } 0704 else if (name3 == QLatin1String("IsExpanded")) 0705 { 0706 if (!val3.isEmpty()) 0707 { 0708 isExpanded = val3.toUInt(); 0709 } 0710 } 0711 else if (name3 == QLatin1String("UrlsList")) 0712 { 0713 for (QDomNode n4 = e3.firstChild() ; !n4.isNull() ; n4 = n4.nextSibling()) 0714 { 0715 QDomElement e4 = n4.toElement(); 0716 QString name4 = e4.tagName(); 0717 QString val4 = e4.attribute(QLatin1String("value")); 0718 0719 if (name4 == QLatin1String("Url")) 0720 { 0721 if (!val4.isEmpty()) 0722 { 0723 urls.append(QUrl::fromLocalFile(val4)); 0724 } 0725 } 0726 } 0727 } 0728 else if (name3 == QLatin1String("CurrentUrl")) 0729 { 0730 curr = val3; 0731 } 0732 } 0733 0734 QString phierarchy = hierarchy.section(QLatin1Char('/'), 0, -3) + QLatin1String("/"); 0735 QTreeWidgetItem* const parent = d->favoritesList->findFavoriteByHierarchy(phierarchy); 0736 0737 if (!parent) 0738 { 0739 continue; 0740 } 0741 0742 ShowfotoStackViewFavoriteItem* const fitem = new ShowfotoStackViewFavoriteItem(parent, type); 0743 fitem->setName(name); 0744 fitem->setHierarchy(hierarchy); 0745 fitem->setExpanded(isExpanded); 0746 0747 if (type == ShowfotoStackViewFavoriteItem::FavoriteItem) 0748 { 0749 fitem->setDescription(desc); 0750 fitem->setDate(date); 0751 fitem->setIcon(0, QIcon::fromTheme(icon)); 0752 0753 if (urls.isEmpty()) 0754 { 0755 delete fitem; 0756 continue; 0757 } 0758 else 0759 { 0760 fitem->setUrls(urls); 0761 } 0762 0763 if (curr.isEmpty()) 0764 { 0765 if (!fitem->urls().isEmpty()) 0766 { 0767 curr = fitem->urls().first().toLocalFile(); 0768 } 0769 else 0770 { 0771 curr = QString(); 0772 } 0773 } 0774 0775 fitem->setCurrentUrl(QUrl::fromLocalFile(curr)); 0776 } 0777 } 0778 } 0779 0780 continue; 0781 } 0782 } 0783 0784 return true; 0785 } 0786 0787 QList<QAction*> ShowfotoStackViewFavorites::pluginActions() const 0788 { 0789 return d->sidebar->pluginActions(); 0790 } 0791 0792 void ShowfotoStackViewFavorites::slotSearchTextChanged(const SearchTextSettings& settings) 0793 { 0794 d->favoritesList->setFilter(settings.text, settings.caseSensitive); 0795 } 0796 0797 void ShowfotoStackViewFavorites::slotSearchResult(int found) 0798 { 0799 d->favoritesFilter->slotSearchResult(found ? true : false); 0800 } 0801 0802 } // namespace ShowFoto 0803 0804 #include "moc_showfotostackviewfavorites.cpp"