void ImageView::LoadAlbumRunnable::run() { while (!m_dirList.empty()) { ThumbItem *dir = m_dirList.takeFirst(); ThumbList children; GalleryUtil::LoadDirectory(children, dir->GetPath(), GalleryFilter(m_sortorder != 0), false, NULL, NULL); { QMutexLocker guard(&m_isAliveLock); if (!m_isAlive) { break; } } // The first images should not always come from the first directory. if (m_slideshow_sequencing > 1) { std::random_shuffle(children.begin(), children.end()); } ThumbList fileList; filterDirectories(children, fileList, m_dirList); if (!fileList.empty()) { m_parent->AddItems(fileList); } } }
void IconView::UpdateText(MythUIButtonListItem *item) { if (!item) { if (m_positionText) m_positionText->Reset(); return; } if (m_positionText) m_positionText->SetText(tr("%1 of %2") .arg(m_imageList->IsEmpty() ? 0 : m_imageList->GetCurrentPos() + 1) .arg(m_imageList->GetCount())); ThumbItem *thumbitem = item->GetData().value<ThumbItem *>(); if (!thumbitem) return; if (m_crumbsText) { QString path = thumbitem->GetPath(); path.replace(m_galleryDir, tr("Gallery Home")); path.replace("/", " > "); m_crumbsText->SetText(path); } if (m_captionText) { QString caption; caption = thumbitem->GetCaption(); caption = (caption.isNull()) ? "" : caption; m_captionText->SetText(caption); } }
void IconView::HandleItemSelect(MythUIButtonListItem *item) { bool handled = false; ThumbItem *thumbitem = item->GetData().value<ThumbItem *>(); if (!thumbitem) return; // if the selected thumbitem is a Media Device // attempt to mount it if it isn't already if (thumbitem->GetMediaDevice()) handled = HandleMediaDeviceSelect(thumbitem); if (!handled && thumbitem->IsDir()) { m_history.push_back(m_imageList->GetCurrentPos()); LoadDirectory(thumbitem->GetPath()); handled = true; } if (!handled) HandleImageSelect("SELECT"); }
void IconView::DoRename(QString folderName) { if (folderName.isEmpty() || folderName == "." || folderName == "..") return; ThumbItem *thumbitem = GetCurrentThumb(); if (!thumbitem) return; if (!GalleryUtil::Rename(m_currDir, thumbitem->GetName(), folderName)) { QString msg; if (thumbitem->IsDir()) msg = tr("Failed to rename folder"); else msg = tr("Failed to rename file"); ShowOkPopup(msg, NULL, NULL); return; } LoadDirectory(m_currDir); }
/** Separate the input into files and directories */ void ImageView::LoadAlbumRunnable::filterDirectories(const ThumbList &input, ThumbList &fileList, ThumbList &dirList) { for (int i = 0; i < input.size(); ++i) { ThumbItem *item = input.at(i); ThumbList &targetList = item->IsDir() ? dirList : fileList; targetList.append(item); } }
void IconView::HandleSelectAll(void) { ThumbItem *item; for (int x = 0; x < m_itemList.size(); x++) { item = m_itemList.at(x); if (!m_itemMarked.contains(item->GetPath())) m_itemMarked.append(item->GetPath()); } m_imageList->SetAllChecked(MythUIButtonListItem::FullChecked); }
void IconView::HandleDeleteCurrent(void) { ThumbItem *thumbitem = GetCurrentThumb(); if (!thumbitem) return; QString title = tr("Delete Current File or Folder"); QString msg = (thumbitem->IsDir()) ? tr("Deleting 1 folder, including any subfolders and files.") : tr("Deleting 1 image."); ShowOkPopup(title + '\n' + msg, this, SLOT(DoDeleteCurrent(bool)), true); }
void IconView::UpdateImage(MythUIButtonListItem *item) { if (!m_selectedImage) return; ThumbItem *thumbitem = item->GetData().value<ThumbItem *>(); QString selectedimage; if (thumbitem) { selectedimage = thumbitem->GetImageFilename(); selectedimage = (selectedimage.isNull()) ? "" : selectedimage; } m_selectedImage->SetFilename(selectedimage); m_selectedImage->Load(); }
void IconView::DoDeleteCurrent(bool doDelete) { if (doDelete) { ThumbItem *thumbitem = GetCurrentThumb(); if (!thumbitem) return; QFileInfo fi; fi.setFile(thumbitem->GetPath()); GalleryUtil::Delete(fi); LoadDirectory(m_currDir); } }
void IconView::HandleRotateCCW(void) { ThumbItem *thumbitem = GetCurrentThumb(); if (!thumbitem || thumbitem->IsDir()) return; int rotAngle = thumbitem->GetRotationAngle(); rotAngle -= 90; if (rotAngle >= 360) rotAngle -= 360; if (rotAngle < 0) rotAngle += 360; thumbitem->SetRotationAngle(rotAngle); }
void IconView::HandleRename(void) { ThumbItem *thumbitem = GetCurrentThumb(); if (!thumbitem) return; QString folderName = thumbitem->GetName(); QString message = tr("Rename"); MythTextInputDialog *dialog = new MythTextInputDialog(m_popupStack, message, FilterNone, false, folderName); if (dialog->Create()) m_popupStack->AddScreen(dialog); connect(dialog, SIGNAL(haveResult(QString)), SLOT(DoRename(QString)), Qt::QueuedConnection); }
bool IconView::HandleImageSelect(const QString &action) { ThumbItem *thumbitem = GetCurrentThumb(); if (!thumbitem || (thumbitem->IsDir() && !m_recurse)) return false; int slideShow = ((action == "PLAY" || action == "SLIDESHOW") ? 1 : (action == "RANDOMSHOW") ? 2 : (action == "SEASONALSHOW" ? 3 : 0)); int pos = m_imageList->GetCurrentPos(); #ifdef USING_OPENGL if (m_useOpenGL && QGLFormat::hasOpenGL()) { GLSDialog gv(m_itemList, &pos, slideShow, m_sortorder, GetMythMainWindow()); gv.exec(); } else #endif { SingleView sv(m_itemList, &pos, slideShow, m_sortorder, GetMythMainWindow()); sv.exec(); } // if the user deleted files while in single view mode // the cached contents of the directory will be out of // sync, reload the current directory to refresh the view LoadDirectory(m_currDir); m_imageList->SetItemCurrent(pos); return true; }
void IconView::DoDeleteCurrent(bool doDelete) { if (doDelete) { ThumbItem *thumbitem = GetCurrentThumb(); int currPos = 0; MythUIButtonListItem *item = m_imageList->GetItemCurrent(); if (item) currPos = m_imageList->GetCurrentPos(); if (!thumbitem) return; QFileInfo fi; fi.setFile(thumbitem->GetPath()); GalleryUtil::Delete(fi); LoadDirectory(m_currDir); m_imageList->SetItemCurrent(currPos); } }
void IconView::DoRename(QString folderName) { if (folderName.isEmpty() || folderName == "." || folderName == "..") return; ThumbItem *thumbitem = GetCurrentThumb(); int currPos = 0; MythUIButtonListItem *item = m_imageList->GetItemCurrent(); if (item) { currPos = m_imageList->GetCurrentPos() + 1; if (currPos >= m_imageList->GetCount()) currPos = m_imageList->GetCount() - 1; } if (!thumbitem) return; if (!GalleryUtil::Rename(m_currDir, thumbitem->GetName(), folderName)) { QString msg; if (thumbitem->IsDir()) msg = tr("Failed to rename folder"); else msg = tr("Failed to rename file"); ShowOkPopup(msg, NULL, NULL); return; } LoadDirectory(m_currDir); m_imageList->SetItemCurrent(currPos); }
bool GalleryUtil::LoadDirectory(ThumbList& itemList, const QString& dir, const GalleryFilter& flt, bool recurse, ThumbHash *itemHash, ThumbGenerator* thumbGen) { QString blah = dir; QDir d(blah); QString currDir = d.absolutePath(); QStringList splitFD; bool isGallery; QFileInfoList gList = d.entryInfoList(QStringList("serial*.dat"), QDir::Files); isGallery = (gList.count() != 0); // Create .thumbcache dir if neccesary if (thumbGen) thumbGen->getThumbcacheDir(currDir); QFileInfoList list = d.entryInfoList(GetMediaFilter(), QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot, (QDir::SortFlag)flt.getSort()); if (list.isEmpty()) return false; QFileInfoList::const_iterator it = list.begin(); const QFileInfo *fi; if (thumbGen) { thumbGen->cancel(); thumbGen->setDirectory(currDir, isGallery); } if (!flt.getDirFilter().isEmpty()) { splitFD = flt.getDirFilter().split(":"); } while (it != list.end()) { fi = &(*it); ++it; // remove these already-resized pictures. if (isGallery && ( (fi->fileName().indexOf(".thumb.") > 0) || (fi->fileName().indexOf(".sized.") > 0) || (fi->fileName().indexOf(".highlight.") > 0))) continue; // skip filtered directory if (fi->isDir() && !splitFD.filter(fi->fileName(), Qt::CaseInsensitive).isEmpty()) continue; if (fi->isDir() && recurse) { LoadDirectory(itemList, QDir::cleanPath(fi->absoluteFilePath()), flt, true, itemHash, thumbGen); } else { if ((GalleryUtil::IsImage(fi->absoluteFilePath()) && flt.getTypeFilter() == kTypeFilterMoviesOnly) || (GalleryUtil::IsMovie(fi->absoluteFilePath()) && flt.getTypeFilter() == kTypeFilterImagesOnly)) continue; ThumbItem *item = new ThumbItem(fi->fileName(), QDir::cleanPath(fi->absoluteFilePath()), fi->isDir()); itemList.append(item); if (itemHash) itemHash->insert(item->GetName(), item); if (thumbGen) thumbGen->addFile(item->GetName()); } } return isGallery; }
void IconView::customEvent(QEvent *event) { if (event->type() == ThumbGenEvent::kEventType) { ThumbGenEvent *tge = dynamic_cast<ThumbGenEvent *>(event); if (!tge) return; ThumbData *td = tge->thumbData; if (!td) return; ThumbItem *thumbitem = m_itemHash.value(td->fileName); if (thumbitem) { int rotateAngle = thumbitem->GetRotationAngle(); if (rotateAngle) { QMatrix matrix; matrix.rotate(rotateAngle); td->thumb = td->thumb.transformed( matrix, Qt::SmoothTransformation); } int pos = m_itemList.indexOf(thumbitem); LoadThumbnail(thumbitem); MythUIButtonListItem *item = m_imageList->GetItemAt(pos); if (QFile(thumbitem->GetImageFilename()).exists()) item->SetImage(thumbitem->GetImageFilename()); if (m_imageList->GetCurrentPos() == pos) UpdateImage(item); } delete td; } else if (event->type() == ChildCountEvent::kEventType) { ChildCountEvent *cce = dynamic_cast<ChildCountEvent *>(event); if (!cce) return; ChildCountData *ccd = cce->childCountData; if (!ccd) return; ThumbItem *thumbitem = m_itemHash.value(ccd->fileName); if (thumbitem) { int pos = m_itemList.indexOf(thumbitem); MythUIButtonListItem *item = m_imageList->GetItemAt(pos); if (item) item->SetText(QString("%1").arg(ccd->count), "childcount"); } delete ccd; } else if (event->type() == DialogCompletionEvent::kEventType) { DialogCompletionEvent *dce = (DialogCompletionEvent*)(event); QString resultid = dce->GetId(); int resultdata = dce->GetData().toInt(); if (resultid == "mainmenu") { switch (resultdata) { case 0: HandleSlideShow(); break; case 1: HandleRandomShow(); break; case 2: break; case 3: break; case 4: HandleSubMenuFilter(); break; case 5: break; case 6: HandleSettings(); break; case 7: HandleSeasonalShow(); break; } } else if (resultid == "metadatamenu") { switch (resultdata) { case 0: HandleRotateCW(); break; case 1: HandleRotateCCW(); break; } } else if (resultid == "markingmenu") { switch (resultdata) { case 0: HandleSelectOne(); break; case 1: HandleClearOneMarked(); break; case 2: HandleSelectAll(); break; case 3: HandleClearMarked(); break; } } else if (resultid == "filemenu") { switch (resultdata) { case 0: HandleShowDevices(); break; case 1: HandleEject(); break; case 2: HandleImport(); break; case 3: HandleCopyHere(); break; case 4: HandleMoveHere(); break; case 5: HandleDelete(); break; case 6: HandleMkDir(); break; case 7: HandleRename(); break; } } m_menuPopup = NULL; } }
bool GalleryUtil::LoadDirectory(ThumbList& itemList, const QString& dir, int sortorder, bool recurse, ThumbHash *itemHash, ThumbGenerator* thumbGen) { QString blah = dir; QDir d(blah); QString currDir = d.absolutePath(); bool isGallery; QFileInfoList gList = d.entryInfoList(QStringList("serial*.dat"), QDir::Files); isGallery = (gList.count() != 0); // Create .thumbcache dir if neccesary if (thumbGen) thumbGen->getThumbcacheDir(currDir); QFileInfoList list = d.entryInfoList(GetMediaFilter(), QDir::Files | QDir::AllDirs, (QDir::SortFlag)sortorder); if (list.isEmpty()) return false; QFileInfoList::const_iterator it = list.begin(); const QFileInfo *fi; if (thumbGen) { thumbGen->cancel(); thumbGen->setDirectory(currDir, isGallery); } while (it != list.end()) { fi = &(*it); ++it; if (fi->fileName() == "." || fi->fileName() == "..") continue; // remove these already-resized pictures. if (isGallery && ( (fi->fileName().indexOf(".thumb.") > 0) || (fi->fileName().indexOf(".sized.") > 0) || (fi->fileName().indexOf(".highlight.") > 0))) continue; if (fi->isDir() && recurse) { GalleryUtil::LoadDirectory( itemList, QDir::cleanPath(fi->absoluteFilePath()), sortorder, true, itemHash, thumbGen); } else { ThumbItem *item = new ThumbItem( fi->fileName(), QDir::cleanPath(fi->absoluteFilePath()), fi->isDir()); itemList.append(item); if (itemHash) itemHash->insert(item->GetName(), item); if (thumbGen) thumbGen->addFile(item->GetName()); } } return isGallery; }
bool IconView::keyPressEvent(QKeyEvent *event) { if (GetFocusWidget()->keyPressEvent(event)) return true; bool handled = false; QStringList actions; handled = GetMythMainWindow()->TranslateKeyPress("Gallery", event, actions); for (int i = 0; i < actions.size() && !handled; i++) { QString action = actions[i]; handled = true; if (!m_itemList.isEmpty()) { if (action == "ROTRIGHT") HandleRotateCW(); else if (action == "ROTLEFT") HandleRotateCCW(); else if (action == "DELETE") HandleDelete(); else if (action == "EDIT") HandleRename(); else if (action == "MARK") { ThumbItem *thumbitem = GetCurrentThumb(); MythUIButtonListItem *item = m_imageList->GetItemCurrent(); if (thumbitem) { if (!m_itemMarked.contains(thumbitem->GetPath())) { m_itemMarked.append(thumbitem->GetPath()); item->setChecked(MythUIButtonListItem::FullChecked); } else { m_itemMarked.removeAll(thumbitem->GetPath()); item->setChecked(MythUIButtonListItem::NotChecked); } } } else if (action == "SLIDESHOW") HandleSlideShow(); else if (action == "RANDOMSHOW") HandleRandomShow(); else if (action == "SEASONALSHOW") HandleSeasonalShow(); else handled = false; } if (action == "ESCAPE") { if (GetMythMainWindow()->IsExitingToMain()) { while ( m_currDir != m_galleryDir && HandleSubDirEscape(m_galleryDir) ); } handled = HandleEscape(); } else if (action == "MENU") { HandleMainMenu(); } } if (!handled && MythScreenType::keyPressEvent(event)) handled = true; return handled; }
void IconView::HandleShowDevices(void) { MediaMonitor *mon = MediaMonitor::GetMediaMonitor(); #ifndef _WIN32 if (m_currDevice && mon && mon->ValidateAndLock(m_currDevice)) { m_currDevice->disconnect(this); mon->Unlock(m_currDevice); } else m_currDir = m_galleryDir; #endif m_currDevice = NULL; m_showDevices = true; while (!m_itemList.isEmpty()) delete m_itemList.takeFirst(); m_itemHash.clear(); m_imageList->Reset(); m_thumbGen->cancel(); m_childCountThread->cancel(); // add gallery directory ThumbItem *item = new ThumbItem("Gallery", m_galleryDir, true); m_itemList.append(item); m_itemHash.insert(item->GetName(), item); if (mon) { MythMediaType type = MythMediaType(MEDIATYPE_DATA | MEDIATYPE_MGALLERY | MEDIATYPE_MVIDEO); QList<MythMediaDevice*> removables = mon->GetMedias(type); QList<MythMediaDevice*>::Iterator it = removables.begin(); for (; it != removables.end(); ++it) { if (mon->ValidateAndLock(*it)) { item = new ThumbItem( (*it)->getVolumeID().isEmpty() ? (*it)->getDevicePath() : (*it)->getVolumeID(), (*it)->getMountPath(), true, *it); m_itemList.append(item); m_itemHash.insert(item->GetName(), item); mon->Unlock(*it); } } } ThumbItem *thumbitem; for (int x = 0; x < m_itemList.size(); x++) { thumbitem = m_itemList.at(x); thumbitem->InitCaption(m_showcaption); MythUIButtonListItem* item = new MythUIButtonListItem(m_imageList, thumbitem->GetCaption(), 0, true, MythUIButtonListItem::NotChecked); item->SetData(qVariantFromValue(thumbitem)); } // exit from menu on show devices action.. SetFocusWidget(m_imageList); }
void IconView::LoadDirectory(const QString &dir) { if (m_thumbGen && m_thumbGen->isRunning()) m_thumbGen->cancel(); if (m_childCountThread && m_childCountThread->isRunning()) m_childCountThread->cancel(); QDir d(dir); if (!d.exists()) { LOG(VB_GENERAL, LOG_ERR, LOC + "LoadDirectory called with " + QString("non-existant directory: '%1'").arg(dir)); return; } m_showDevices = false; m_currDir = d.absolutePath(); while (!m_itemList.isEmpty()) delete m_itemList.takeFirst(); m_itemHash.clear(); m_imageList->Reset(); m_isGallery = GalleryUtil::LoadDirectory(m_itemList, dir, *m_galleryFilter, false, &m_itemHash, m_thumbGen); if (m_thumbGen && !m_thumbGen->isRunning()) m_thumbGen->start(); ThumbItem *thumbitem; for (int x = 0; x < m_itemList.size(); x++) { thumbitem = m_itemList.at(x); thumbitem->InitCaption(m_showcaption); MythUIButtonListItem* item = new MythUIButtonListItem(m_imageList, thumbitem->GetCaption(), 0, true, MythUIButtonListItem::NotChecked); item->SetData(qVariantFromValue(thumbitem)); if (thumbitem->IsDir()) { item->DisplayState("subfolder", "nodetype"); m_childCountThread->addFile(thumbitem->GetPath()); } LoadThumbnail(thumbitem); if (QFile(thumbitem->GetImageFilename()).exists()) item->SetImage(thumbitem->GetImageFilename()); if (m_itemMarked.contains(thumbitem->GetPath())) item->setChecked(MythUIButtonListItem::FullChecked); } if (m_childCountThread && !m_childCountThread->isRunning()) m_childCountThread->start(); if (m_noImagesText) m_noImagesText->SetVisible(m_itemList.isEmpty()); if (!m_itemList.isEmpty()) { UpdateText(m_imageList->GetItemCurrent()); UpdateImage(m_imageList->GetItemCurrent()); } }