00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <cmath>
00020
00021
00022 #include <algorithm>
00023 using namespace std;
00024
00025
00026 #include <qevent.h>
00027 #include <qimage.h>
00028 #include <qdir.h>
00029
00030
00031 #include <mythtv/mythcontext.h>
00032 #include <mythtv/uitypes.h>
00033 #include <mythtv/uilistbtntype.h>
00034 #include <mythtv/xmlparse.h>
00035 #include <mythtv/dialogbox.h>
00036 #include <mythtv/mythdbcon.h>
00037 #include <mythtv/mythdialogs.h>
00038 #include <mythtv/mythmediamonitor.h>
00039
00040
00041 #include "galleryutil.h"
00042 #include "gallerysettings.h"
00043 #include "thumbgenerator.h"
00044 #include "iconview.h"
00045 #include "singleview.h"
00046 #include "glsingleview.h"
00047
00048 #include "constants.h"
00049
00050 #define LOC QString("IconView: ")
00051 #define LOC_ERR QString("IconView, Error: ")
00052
00053 IconView::IconView(const QString &galleryDir,
00054 MythMediaDevice *initialDevice,
00055 MythMainWindow *parent)
00056 : MythDialog(parent, "IconView"),
00057 m_galleryDir(galleryDir),
00058
00059 m_theme(NULL), m_menuRect(0,0,0,0),
00060 m_textRect(0,0,0,0), m_viewRect(0,0,0,0),
00061
00062 m_inMenu(false), m_inSubMenu(false),
00063 m_menuType(NULL), m_submenuType(NULL),
00064
00065 m_isGallery(false), m_showDevices(false),
00066 m_currDir(QString::null),
00067 m_currDevice(initialDevice),
00068
00069 m_currRow(0), m_currCol(0),
00070 m_lastRow(0), m_lastCol(0),
00071 m_topRow(0),
00072 m_nRows(0), m_nCols(0),
00073
00074 m_spaceW(0), m_spaceH(0),
00075 m_thumbW(0), m_thumbH(0),
00076
00077 m_thumbGen(new ThumbGenerator(
00078 this,
00079 (int)(m_thumbW - 10 * wmult),
00080 (int)(m_thumbH - 10 * hmult))),
00081
00082 m_showcaption(gContext->GetNumSetting("GalleryOverlayCaption", 0)),
00083 m_sortorder(gContext->GetNumSetting("GallerySortOrder", 0)),
00084 m_useOpenGL(gContext->GetNumSetting("SlideshowUseOpenGL", 0)),
00085 m_recurse(gContext->GetNumSetting("GalleryRecursiveSlideshow", 0)),
00086 m_paths(QStringList::split(
00087 ":", gContext->GetSetting("GalleryImportDirs"))),
00088 m_errorStr(QString::null)
00089 {
00090 m_itemList.setAutoDelete(true);
00091 m_itemDict.setAutoDelete(false);
00092
00093 setNoErase();
00094
00095 QDir dir(m_galleryDir);
00096 if (!dir.exists() || !dir.isReadable())
00097 {
00098 m_errorStr = tr("MythGallery Directory '%1' does not exist "
00099 "or is unreadable.").arg(m_galleryDir);
00100 return;
00101 }
00102
00103 if (!LoadTheme())
00104 {
00105 m_errorStr = tr("MythGallery failed to load theme, "
00106 "see console for details.");
00107 return;
00108 }
00109
00110 updateBackground();
00111
00112 SetupMediaMonitor();
00113
00114 srand(time(NULL));
00115 }
00116
00117 IconView::~IconView()
00118 {
00119 ClearMenu(m_submenuType);
00120 ClearMenu(m_menuType);
00121
00122 if (m_thumbGen)
00123 {
00124 delete m_thumbGen;
00125 m_thumbGen = NULL;
00126 }
00127
00128 if (m_theme)
00129 {
00130 delete m_theme;
00131 m_theme = NULL;
00132 }
00133 }
00134
00135 void IconView::SetupMediaMonitor(void)
00136 {
00137 #ifndef _WIN32
00138 MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
00139 if (m_currDevice && mon && mon->ValidateAndLock(m_currDevice))
00140 {
00141 bool mounted = m_currDevice->isMounted(true);
00142 if (!mounted)
00143 mounted = m_currDevice->mount();
00144
00145 if (mounted)
00146 {
00147 connect(m_currDevice,
00148 SIGNAL(statusChanged(MediaStatus, MythMediaDevice*)),
00149 SLOT(mediaStatusChanged(MediaStatus, MythMediaDevice*)));
00150
00151 LoadDirectory(m_currDevice->getMountPath(), true);
00152
00153 mon->Unlock(m_currDevice);
00154 return;
00155 }
00156 else
00157 {
00158 DialogBox *dlg = new DialogBox(gContext->GetMainWindow(),
00159 tr("Failed to mount device: ") +
00160 m_currDevice->getDevicePath() + "\n\n" +
00161 tr("Showing the default MythGallery directory."));
00162 dlg->AddButton(tr("OK"));
00163 dlg->exec();
00164 dlg->deleteLater();
00165 mon->Unlock(m_currDevice);
00166 }
00167 }
00168 m_currDevice = NULL;
00169 LoadDirectory(m_galleryDir, true);
00170 #endif // _WIN32
00171 }
00172
00173 void IconView::paintEvent(QPaintEvent *e)
00174 {
00175 if (e->rect().intersects(m_menuRect))
00176 UpdateMenu();
00177 if (e->rect().intersects(m_textRect))
00178 UpdateText();
00179 if (e->rect().intersects(m_viewRect))
00180 UpdateView();
00181 }
00182
00183 void IconView::updateBackground(void)
00184 {
00185 QPixmap bground(size());
00186 bground.fill(this, 0, 0);
00187
00188 QPainter tmp(&bground);
00189
00190 LayerSet *container = m_theme->GetSet("background");
00191 if (container)
00192 {
00193 container->Draw(&tmp, 0, 0);
00194 }
00195
00196 tmp.end();
00197 m_background = bground;
00198
00199 setPaletteBackgroundPixmap(m_background);
00200 }
00201
00202 void IconView::UpdateMenu(void)
00203 {
00204 QPixmap pix(m_menuRect.size());
00205 pix.fill(this, m_menuRect.topLeft());
00206 QPainter p(&pix);
00207
00208 LayerSet *container = m_theme->GetSet("menu");
00209 if (container)
00210 {
00211 container->Draw(&p, 0, 0);
00212 container->Draw(&p, 1, 0);
00213 container->Draw(&p, 2, 0);
00214 container->Draw(&p, 3, 0);
00215 container->Draw(&p, 4, 0);
00216 container->Draw(&p, 5, 0);
00217 container->Draw(&p, 6, 0);
00218 container->Draw(&p, 7, 0);
00219 container->Draw(&p, 8, 0);
00220 }
00221 p.end();
00222
00223 bitBlt(this, m_menuRect.left(), m_menuRect.top(),
00224 &pix, 0, 0, -1, -1, Qt::CopyROP);
00225 }
00226
00227 void IconView::UpdateText(void)
00228 {
00229 QPixmap pix(m_textRect.size());
00230 pix.fill(this, m_textRect.topLeft());
00231 QPainter p(&pix);
00232
00233 LayerSet *container = m_theme->GetSet("text");
00234 if (container)
00235 {
00236 UITextType *ttype = (UITextType*) container->GetType("text");
00237 if (ttype)
00238 {
00239 ThumbItem *item = m_itemList.at(m_currRow * m_nCols + m_currCol);
00240
00241 QString caption = "";
00242 if (item)
00243 {
00244 item->InitCaption(m_showcaption);
00245 caption = item->GetCaption();
00246 caption = (caption.isNull()) ? "" : caption;
00247 }
00248 ttype->SetText(caption);
00249 }
00250
00251 container->Draw(&p, 0, 0);
00252 container->Draw(&p, 1, 0);
00253 container->Draw(&p, 2, 0);
00254 container->Draw(&p, 3, 0);
00255 container->Draw(&p, 4, 0);
00256 container->Draw(&p, 5, 0);
00257 container->Draw(&p, 6, 0);
00258 container->Draw(&p, 7, 0);
00259 container->Draw(&p, 8, 0);
00260 }
00261 p.end();
00262
00263 bitBlt(this, m_textRect.left(), m_textRect.top(),
00264 &pix, 0, 0, -1, -1, Qt::CopyROP);
00265 }
00266
00267 void IconView::UpdateView(void)
00268 {
00269 QPixmap pix(m_viewRect.size());
00270 pix.fill(this, m_viewRect.topLeft());
00271 QPainter p(&pix);
00272 p.setPen(Qt::white);
00273
00274 LayerSet *container = m_theme->GetSet("view");
00275 if (container)
00276 {
00277 int upArrow = (m_topRow == 0) ? 0 : 1;
00278 int dnArrow = (m_currRow == m_lastRow) ? 0 : 1;
00279
00280 container->Draw(&p, 0, upArrow);
00281 container->Draw(&p, 1, dnArrow);
00282 }
00283
00284 int bw = m_backRegPix.width();
00285 int bh = m_backRegPix.height();
00286 int bw2 = m_backRegPix.width()/2;
00287 int bh2 = m_backRegPix.height()/2;
00288 int sw = (int)(7*wmult);
00289 int sh = (int)(7*hmult);
00290
00291 int curPos = m_topRow*m_nCols;
00292
00293 for (int y = 0; y < m_nRows; y++)
00294 {
00295 int ypos = m_spaceH * (y + 1) + m_thumbH * y;
00296
00297 for (int x = 0; x < m_nCols; x++)
00298 {
00299 if (curPos >= (int)m_itemList.count())
00300 continue;
00301
00302 ThumbItem *item = m_itemList.at(curPos);
00303 if (!item->GetPixmap())
00304 LoadThumbnail(item);
00305
00306 int xpos = m_spaceW * (x + 1) + m_thumbW * x;
00307
00308 if (item->IsDir())
00309 {
00310 if (curPos == (m_currRow*m_nCols+m_currCol))
00311 p.drawPixmap(xpos, ypos, m_folderSelPix);
00312 else
00313 p.drawPixmap(xpos, ypos, m_folderRegPix);
00314
00315 if (item->GetPixmap())
00316 {
00317 p.drawPixmap(xpos + sw, ypos + sh + (int)(15 * hmult),
00318 *item->GetPixmap(),
00319 item->GetPixmap()->width() / 2 - bw2 + sw,
00320 item->GetPixmap()->height() / 2 - bh2 + sh,
00321 bw - 2 * sw, bh - 2 * sh - (int)(15 * hmult));
00322 }
00323
00324 if (m_itemMarked.contains(item->GetPath()))
00325 p.drawPixmap(xpos, ypos, m_MrkPix);
00326
00327 }
00328 else
00329 {
00330 if (curPos == (m_currRow*m_nCols+m_currCol))
00331 p.drawPixmap(xpos, ypos, m_backSelPix);
00332 else
00333 p.drawPixmap(xpos, ypos, m_backRegPix);
00334
00335 if (item->GetPixmap())
00336 {
00337 p.drawPixmap(xpos + sw, ypos + sh,
00338 *item->GetPixmap(),
00339 item->GetPixmap()->width() / 2 - bw2 + sw,
00340 item->GetPixmap()->height() / 2 - bh2 + sh,
00341 bw - 2 * sw, bh - 2 * sh);
00342 }
00343
00344 if (m_itemMarked.contains(item->GetPath()))
00345 p.drawPixmap(xpos, ypos, m_MrkPix);
00346 }
00347
00348 curPos++;
00349 }
00350 }
00351
00352 p.end();
00353
00354 bitBlt(this, m_viewRect.left(), m_viewRect.top(),
00355 &pix, 0, 0, -1, -1, Qt::CopyROP);
00356 }
00357
00358 static bool has_action(QString action, const QStringList &actions)
00359 {
00360 QStringList::const_iterator it;
00361 for (it = actions.begin(); it != actions.end(); ++it)
00362 {
00363 if (action == *it)
00364 return true;
00365 }
00366 return false;
00367 }
00368
00369 void IconView::keyPressEvent(QKeyEvent *e)
00370 {
00371 if (!e) return;
00372
00373 bool handled = false;
00374 bool menuHandled = false;
00375
00376 QStringList actions;
00377 gContext->GetMainWindow()->TranslateKeyPress("Gallery", e, actions);
00378
00379 for (uint i = 0; i < actions.size() && !handled && !menuHandled; i++)
00380 {
00381 QString action = actions[i];
00382 if (action == "MENU")
00383 {
00384 m_inMenu = !m_inMenu;
00385 m_menuType->SetActive(m_inMenu & !m_inSubMenu);
00386 m_submenuType->SetActive(m_inMenu & m_inSubMenu);
00387 menuHandled = true;
00388 }
00389 else if (action == "ESCAPE")
00390 {
00391 if (!m_parent->IsExitingToMain())
00392 {
00393 if (m_inMenu & m_inSubMenu)
00394 {
00395 HandleMainMenu();
00396 m_menuType->SetActive(m_inMenu & !m_inSubMenu);
00397 m_submenuType->SetActive(m_inMenu & m_inSubMenu);
00398 menuHandled = true;
00399 }
00400 }
00401 }
00402 else if (action == "UP")
00403 {
00404 if (m_inMenu & !m_inSubMenu)
00405 {
00406 m_menuType->MoveUp();
00407 menuHandled = true;
00408 }
00409 else if (m_inMenu & m_inSubMenu)
00410 {
00411 m_submenuType->MoveUp();
00412 menuHandled = true;
00413 }
00414 else
00415 {
00416 handled = MoveUp();
00417 }
00418 }
00419 else if (action == "DOWN")
00420 {
00421 if (m_inMenu & !m_inSubMenu)
00422 {
00423 m_menuType->MoveDown();
00424 menuHandled = true;
00425 }
00426 else if (m_inMenu & m_inSubMenu)
00427 {
00428 m_submenuType->MoveDown();
00429 menuHandled = true;
00430 }
00431 else
00432 {
00433 handled = MoveDown();
00434 }
00435 }
00436 else if (action == "LEFT")
00437 {
00438 handled = MoveLeft();
00439 }
00440 else if (action == "RIGHT")
00441 {
00442 handled = MoveRight();
00443 }
00444 else if (action == "PAGEUP")
00445 {
00446 bool h = true;
00447 for (int i = 0; i < m_nRows && h; i++)
00448 h = MoveUp();
00449 handled = true;
00450 }
00451 else if (action == "PAGEDOWN")
00452 {
00453 bool h = true;
00454 for (int i = 0; i < m_nRows && h; i++)
00455 h = MoveDown();
00456 handled = true;
00457 }
00458 else if (action == "HOME")
00459 {
00460 m_topRow = m_currRow = m_currCol = 0;
00461 handled = true;
00462 }
00463 else if (action == "END")
00464 {
00465 m_currRow = m_lastRow;
00466 m_currCol = m_lastCol;
00467 m_topRow = QMAX(m_currRow-(m_nRows-1),0);
00468 handled = true;
00469 }
00470 else if (action == "ROTRIGHT")
00471 {
00472 HandleRotateCW();
00473 handled = true;
00474 }
00475 else if (action == "ROTLEFT")
00476 {
00477 HandleRotateCCW();
00478 handled = true;
00479 }
00480 else if (action == "DELETE")
00481 {
00482 HandleDelete();
00483 handled = true;
00484 }
00485 else if (action == "MARK")
00486 {
00487 int pos = m_currRow * m_nCols + m_currCol;
00488 ThumbItem *item = m_itemList.at(pos);
00489 if (!item)
00490 {
00491 VERBOSE(VB_IMPORTANT, LOC_ERR + "The impossible happened");
00492 break;
00493 }
00494
00495 if (!m_itemMarked.contains(item->GetPath()))
00496 m_itemMarked.append(item->GetPath());
00497 else
00498 m_itemMarked.remove(item->GetPath());
00499
00500 handled = true;
00501 }
00502 else if (m_inMenu && (action == "SELECT" || action == "PLAY"))
00503 {
00504 HandleMenuButtonPress();
00505 menuHandled = true;
00506 }
00507 else if (action == "SELECT" || action == "PLAY" ||
00508 action == "SLIDESHOW" || action == "RANDOMSHOW")
00509 {
00510 handled = HandleItemSelect(action);
00511 }
00512 }
00513
00514 if (!handled && !menuHandled)
00515 {
00516 gContext->GetMainWindow()->TranslateKeyPress("Global", e, actions);
00517 if (has_action("ESCAPE", actions) && !m_parent->IsExitingToMain())
00518 handled = HandleEscape();
00519 }
00520
00521 if (handled || menuHandled)
00522 update();
00523 else
00524 MythDialog::keyPressEvent(e);
00525 }
00526
00527 bool IconView::HandleItemSelect(const QString &action)
00528 {
00529 bool handled = false;
00530
00531 int pos = m_currRow * m_nCols + m_currCol;
00532 ThumbItem *item = m_itemList.at(pos);
00533 if (!item)
00534 {
00535 VERBOSE(VB_IMPORTANT, LOC_ERR + "Item not found at " +
00536 QString("%1,%2").arg(m_currRow).arg(m_currCol));
00537 return handled;
00538 }
00539
00540 QFileInfo fi(item->GetPath());
00541
00542 if (action == "SELECT" || action == "PLAY")
00543 {
00544
00545
00546 if (item->GetMediaDevice())
00547 handled = HandleMediaDeviceSelect(item);
00548
00549 if (!handled && item->IsDir())
00550 {
00551 LoadDirectory(item->GetPath(), true);
00552 handled = true;
00553 }
00554 }
00555
00556 if (!handled)
00557 handled = HandleImageSelect(action);
00558
00559 return handled;
00560 }
00561
00562 bool IconView::HandleMediaDeviceSelect(ThumbItem *item)
00563 {
00564 MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
00565 if (mon && mon->ValidateAndLock(item->GetMediaDevice()))
00566 {
00567 m_currDevice = item->GetMediaDevice();
00568
00569 if (!m_currDevice->isMounted())
00570 m_currDevice->mount();
00571
00572 item->SetPath(m_currDevice->getMountPath(), true);
00573
00574 connect(m_currDevice,
00575 SIGNAL(statusChanged(MediaStatus,
00576 MythMediaDevice*)),
00577 SLOT(mediaStatusChanged(MediaStatus,
00578 MythMediaDevice*)));
00579
00580 LoadDirectory(m_currDevice->getMountPath(), true);
00581
00582 mon->Unlock(m_currDevice);
00583 }
00584 else
00585 {
00586
00587 MythPopupBox::showOkPopup(
00588 gContext->GetMainWindow(),
00589 tr("Error"),
00590 tr("The selected device is no longer available"));
00591
00592 HandleShowDevices();
00593 m_currRow = 0;
00594 m_currCol = 0;
00595 }
00596
00597 return true;
00598 }
00599
00600 void IconView::HandleSlideShow(void)
00601 {
00602 HandleImageSelect("SLIDESHOW");
00603 }
00604
00605 void IconView::HandleRandomShow(void)
00606 {
00607 HandleImageSelect("RANDOMSHOW");
00608 }
00609
00610 bool IconView::HandleImageSelect(const QString &action)
00611 {
00612 int pos = m_currRow * m_nCols + m_currCol;
00613 ThumbItem *item = m_itemList.at(pos);
00614 if (!item || (item->IsDir() && !m_recurse))
00615 return false;
00616
00617 int slideShow = ((action == "PLAY" || action == "SLIDESHOW") ? 1 :
00618 (action == "RANDOMSHOW") ? 2 : 0);
00619
00620 #ifdef USING_OPENGL
00621 if (m_useOpenGL)
00622 {
00623 if (QGLFormat::hasOpenGL())
00624 {
00625 GLSDialog gv(m_itemList, pos,
00626 slideShow, m_sortorder,
00627 gContext->GetMainWindow());
00628 gv.exec();
00629 }
00630 else
00631 {
00632 MythPopupBox::showOkPopup(
00633 gContext->GetMainWindow(),
00634 tr("Error"),
00635 tr("Sorry: OpenGL support not available"));
00636 }
00637 }
00638 else
00639 #endif
00640 {
00641 SingleView sv(m_itemList, pos, slideShow, m_sortorder,
00642 gContext->GetMainWindow());
00643 sv.exec();
00644 }
00645
00646
00647
00648
00649 LoadDirectory(m_currDir, true);
00650
00651
00652
00653 pos = min((uint)pos, m_itemList.count());
00654 m_currRow = pos / m_nCols;
00655 m_currCol = pos - (m_currRow * m_nCols);
00656 m_topRow = max(0, m_currRow + 1 - m_nRows);
00657
00658 return true;
00659 }
00660
00661 bool IconView::HandleMediaEscape(MediaMonitor *mon)
00662 {
00663
00664
00665 bool handled = false;
00666 QDir curdir(m_currDir);
00667 QValueList<MythMediaDevice*> removables = mon->GetMedias(MEDIATYPE_DATA);
00668 QValueList<MythMediaDevice*>::iterator it = removables.begin();
00669 for (; !handled && (it != removables.end()); it++)
00670 {
00671 if (!mon->ValidateAndLock(*it))
00672 continue;
00673
00674 if (curdir == QDir((*it)->getMountPath()))
00675 {
00676 HandleShowDevices();
00677
00678
00679 ThumbItem *item = NULL;
00680 if (!(*it)->getVolumeID().isEmpty())
00681 item = m_itemDict.find((*it)->getVolumeID());
00682 else
00683 item = m_itemDict.find((*it)->getDevicePath());
00684
00685 if (item)
00686 {
00687 int pos = m_itemList.find(item);
00688 if (pos != -1)
00689 {
00690 m_currRow = pos / m_nCols;
00691 m_currCol = pos - (m_currRow * m_nCols);
00692 m_topRow = max(0, m_currRow + 1 - m_nRows);
00693 }
00694 }
00695
00696 handled = true;
00697 }
00698 else
00699 {
00700 handled = HandleSubDirEscape((*it)->getMountPath());
00701 }
00702
00703 mon->Unlock(*it);
00704 }
00705
00706
00707
00708 return handled;
00709 }
00710
00711 static bool is_subdir(const QDir &parent, const QDir &subdir)
00712 {
00713 QString pstr = parent.canonicalPath();
00714 QString cstr = subdir.canonicalPath();
00715 bool ret = !cstr.find(pstr);
00716
00717
00718 return ret;
00719 }
00720
00721 bool IconView::HandleSubDirEscape(const QString &parent)
00722 {
00723 bool handled = false;
00724
00725 QDir curdir(m_currDir);
00726 QDir pdir(parent);
00727 if ((curdir != pdir) && is_subdir(pdir, curdir))
00728 {
00729 QString oldDirName = curdir.dirName();
00730 curdir.cdUp();
00731 LoadDirectory(curdir.absPath(), true);
00732
00733
00734 ThumbItem *item = m_itemDict.find(oldDirName);
00735 if (item)
00736 {
00737 int pos = m_itemList.find(item);
00738 if (pos != -1)
00739 {
00740 m_currRow = pos / m_nCols;
00741 m_currCol = pos - (m_currRow * m_nCols);
00742 m_topRow = max(0, m_currRow + 1 - m_nRows);
00743 }
00744 }
00745
00746 handled = true;
00747 }
00748
00749 return handled;
00750 }
00751
00752 bool IconView::HandleEscape(void)
00753 {
00754
00755
00756
00757 bool handled = false;
00758
00759
00760 if (m_showDevices)
00761 {
00762
00763 return false;
00764 }
00765
00766
00767 MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
00768 if (mon && m_currDevice)
00769 handled = HandleMediaEscape(mon);
00770
00771
00772
00773 if (!handled)
00774 handled = HandleSubDirEscape(m_galleryDir);
00775
00776
00777
00778 return handled;
00779 }
00780
00781 void IconView::customEvent(QCustomEvent *e)
00782 {
00783 if (!e || (e->type() != QEvent::User))
00784 return;
00785
00786 ThumbData *td = (ThumbData*) (e->data());
00787 if (!td) return;
00788
00789 ThumbItem *item = m_itemDict.find(td->fileName);
00790 if (item)
00791 {
00792 item->SetPixmap(NULL);
00793
00794 int rotateAngle = item->GetRotationAngle();
00795
00796 if (rotateAngle)
00797 {
00798 QWMatrix matrix;
00799 matrix.rotate(rotateAngle);
00800 td->thumb = td->thumb.xForm(matrix);
00801 }
00802
00803
00804 int pos = m_itemList.find(item);
00805
00806 if ((m_topRow*m_nCols <= pos) &&
00807 (pos <= (m_topRow*m_nCols + m_nRows*m_nCols)))
00808 update(m_viewRect);
00809
00810 }
00811 delete td;
00812
00813 }
00814
00815 bool IconView::LoadTheme(void)
00816 {
00817 m_theme = new XMLParse();
00818 m_theme->SetWMult(wmult);
00819 m_theme->SetHMult(hmult);
00820
00821 QDomElement xmldata;
00822 m_theme->LoadTheme(xmldata, "gallery", "gallery-");
00823
00824 for (QDomNode child = xmldata.firstChild(); !child.isNull();
00825 child = child.nextSibling())
00826 {
00827 QDomElement e = child.toElement();
00828 if (!e.isNull())
00829 {
00830 if (e.tagName() == "font")
00831 {
00832 m_theme->parseFont(e);
00833 }
00834 else if (e.tagName() == "container")
00835 {
00836 QRect area;
00837 QString name;
00838 int context;
00839 m_theme->parseContainer(e, name, context, area);
00840
00841 if (name.lower() == "menu")
00842 m_menuRect = area;
00843 else if (name.lower() == "text")
00844 m_textRect = area;
00845 else if (name.lower() == "view")
00846 m_viewRect = area;
00847 }
00848 else
00849 {
00850 VERBOSE(VB_IMPORTANT, LOC_ERR +
00851 "Unknown element: " << e.tagName());
00852 return false;
00853 }
00854 }
00855 }
00856
00857 return LoadMenuTheme() && LoadViewTheme() && LoadThemeImages();
00858 }
00859
00860 static UIListBtnType* get_button(LayerSet *container, const QString &name)
00861 {
00862 UIListBtnType *btn = (UIListBtnType*) container->GetType(name);
00863 if (!btn)
00864 {
00865 VERBOSE(VB_IMPORTANT, LOC_ERR +
00866 QString("Failed to get %1 area.").arg(name));
00867 }
00868 return btn;
00869 }
00870
00871 bool IconView::LoadMenuTheme(void)
00872 {
00873 LayerSet *container = m_theme->GetSet("menu");
00874 if (!container)
00875 {
00876 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to get menu container.");
00877 return false;
00878 }
00879
00880 m_menuType = get_button(container, "menu");
00881 m_submenuType = get_button(container, "submenu");
00882 if (!m_menuType || !m_submenuType)
00883 return false;
00884
00885
00886 UIListBtnTypeItem *item;
00887 item = new UIListBtnTypeItem(m_menuType, tr("SlideShow"));
00888 item->setData(new MenuAction(&IconView::HandleSlideShow));
00889 item = new UIListBtnTypeItem(m_menuType, tr("Random"));
00890 item->setData(new MenuAction(&IconView::HandleRandomShow));
00891 item = new UIListBtnTypeItem(m_menuType, tr("Meta Data..."));
00892 item->setData(new MenuAction(&IconView::HandleSubMenuMetadata));
00893 item = new UIListBtnTypeItem(m_menuType, tr("Marking..."));
00894 item->setData(new MenuAction(&IconView::HandleSubMenuMark));
00895 item = new UIListBtnTypeItem(m_menuType, tr("File..."));
00896 item->setData(new MenuAction(&IconView::HandleSubMenuFile));
00897 item = new UIListBtnTypeItem(m_menuType, tr("Settings"));
00898 item->setData(new MenuAction(&IconView::HandleSettings));
00899
00900
00901 m_menuType->SetActive(false);
00902
00903 return true;
00904 }
00905
00906 bool IconView::LoadViewTheme(void)
00907 {
00908 LayerSet *container = m_theme->GetSet("view");
00909 if (!container)
00910 {
00911 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to get view container.");
00912 return false;
00913 }
00914
00915 UIBlackHoleType *bhType = (UIBlackHoleType*) container->GetType("view");
00916 if (!bhType)
00917 {
00918 VERBOSE(VB_IMPORTANT, LOC_ERR + "Failed to get view area.");
00919 return false;
00920 }
00921
00922 m_iconRect = bhType->getScreenArea();
00923
00924 return true;
00925 }
00926
00927 bool load_pixmap(const QString &name, QPixmap &dest)
00928 {
00929 QImage *img = gContext->LoadScaleImage(name);
00930 if (img)
00931 {
00932 dest = QPixmap(*img);
00933 delete img;
00934
00935 return true;
00936 }
00937
00938 VERBOSE(VB_IMPORTANT, LOC_ERR + QString("Failed to load '%1'").arg(name));
00939 return false;
00940 }
00941
00942 bool IconView::LoadThemeImages(void)
00943 {
00944 bool ok = true;
00945 ok &= load_pixmap("gallery-back-reg.png", m_backRegPix);
00946 ok &= load_pixmap("gallery-back-sel.png", m_backSelPix);
00947 ok &= load_pixmap("gallery-folder-reg.png", m_folderRegPix);
00948 ok &= load_pixmap("gallery-folder-sel.png", m_folderSelPix);
00949 ok &= load_pixmap("gallery-mark.png", m_MrkPix);
00950
00951 if (ok)
00952 {
00953 m_thumbW = m_backRegPix.width();
00954 m_thumbH = m_backRegPix.height();
00955 m_nCols = m_iconRect.width() / m_thumbW;
00956 m_nRows = m_iconRect.height() / m_thumbH;
00957 m_spaceW = (m_iconRect.width()-(m_nCols*m_thumbW)) / (m_nCols + 1);
00958 m_spaceH = (m_iconRect.height()-(m_nRows*m_thumbH)) / (m_nRows + 1);
00959
00960 m_thumbGen->setSize((int)(m_thumbW - 10 * wmult),
00961 (int)(m_thumbH - 10 * hmult));
00962 }
00963
00964 return ok;
00965 }
00966
00967 void IconView::LoadDirectory(const QString &dir, bool topleft)
00968 {
00969 QDir d(dir);
00970 if (!d.exists())
00971 {
00972 VERBOSE(VB_IMPORTANT, LOC_ERR + "LoadDirectory called with " +
00973 QString("non-existant directory: '%1'").arg(dir));
00974 return;
00975 }
00976
00977 m_showDevices = false;
00978
00979 m_currDir = d.absPath();
00980 m_itemList.clear();
00981 m_itemDict.clear();
00982
00983 m_isGallery = GalleryUtil::LoadDirectory(m_itemList, dir, m_sortorder,
00984 false, &m_itemDict, m_thumbGen);
00985
00986 m_lastRow = max((int)ceilf((float)m_itemList.count() /
00987 (float)m_nCols) - 1, 0);
00988 m_lastCol = max(m_itemList.count() - m_lastRow * m_nCols - 1, (uint)0);
00989
00990 if (topleft)
00991 {
00992 m_currRow = 0;
00993 m_currCol = 0;
00994 m_topRow = 0;
00995 }
00996 else
00997 {
00998 uint currIndx = m_currRow * m_nCols + m_currCol;
00999 uint lastIndx = m_itemList.count() - 1;
01000 if (currIndx > lastIndx)
01001 {
01002 m_currRow = lastIndx / m_nCols;
01003 m_currCol = lastIndx % m_nCols;
01004 m_topRow = min(m_topRow, m_currRow);
01005 }
01006 }
01007 }
01008
01009 void IconView::LoadThumbnail(ThumbItem *item)
01010 {
01011 if (!item)
01012 return;
01013
01014 bool canLoadGallery = m_isGallery;
01015 QImage image;
01016
01017 if (canLoadGallery)
01018 {
01019 if (item->IsDir())
01020 {
01021
01022 QDir subdir(item->GetPath(), "*.highlight.*",
01023 QDir::Name, QDir::Files);
01024
01025 if (subdir.count() > 0)
01026 {
01027
01028 QString path =
01029 subdir.entryInfoList()->getFirst()->absFilePath();
01030 image.load(path);
01031 }
01032 }
01033 else
01034 {
01035 QString fn = item->GetName();
01036 int firstDot = fn.find('.');
01037 if (firstDot > 0)
01038 {
01039 fn.insert(firstDot, ".thumb");
01040 QString galThumbPath(m_currDir + "/" + fn);
01041 image.load(galThumbPath);
01042 }
01043 }
01044
01045 canLoadGallery = !(image.isNull());
01046 }
01047
01048 if (!canLoadGallery)
01049 {
01050 QString cachePath =
01051 m_thumbGen->getThumbcacheDir(m_currDir) + item->GetName();
01052
01053 image.load(cachePath);
01054 }
01055
01056 if (!image.isNull())
01057 {
01058 int rotateAngle = 0;
01059
01060 rotateAngle = item->GetRotationAngle();
01061
01062 if (rotateAngle != 0)
01063 {
01064 QWMatrix matrix;
01065 matrix.rotate(rotateAngle);
01066 image = image.xForm(matrix);
01067 }
01068
01069 item->SetPixmap(new QPixmap(image));
01070 }
01071 }
01072
01073 bool IconView::MoveUp(void)
01074 {
01075 if (m_currRow == 0)
01076 return false;
01077
01078 m_currRow--;
01079 m_topRow = min(m_currRow, m_topRow);
01080
01081 return true;
01082 }
01083
01084 bool IconView::MoveDown(void)
01085 {
01086 if (m_currRow == m_lastRow)
01087 return false;
01088
01089 m_currRow++;
01090 if (m_currRow >= m_topRow + m_nRows)
01091 m_topRow++;
01092
01093 if (m_currRow == m_lastRow)
01094 m_currCol = min(m_currCol, m_lastCol);
01095
01096 return true;
01097 }
01098
01099 bool IconView::MoveLeft(void)
01100 {
01101 if (m_currRow == 0 && m_currCol == 0)
01102 return false;
01103
01104 m_currCol--;
01105 if (m_currCol < 0)
01106 {
01107 m_currCol = m_nCols - 1;
01108 m_currRow--;
01109 if (m_currRow < m_topRow)
01110 m_topRow = m_currRow;
01111 }
01112
01113 return true;
01114 }
01115
01116 bool IconView::MoveRight(void)
01117 {
01118 if (m_currRow * m_nCols + m_currCol >= (int)m_itemList.count() - 1)
01119 return false;
01120
01121 m_currCol++;
01122 if (m_currCol >= m_nCols)
01123 {
01124 m_currCol = 0;
01125 m_currRow++;
01126 if (m_currRow >= m_topRow+m_nRows)
01127 m_topRow++;
01128 }
01129
01130 return true;
01131 }
01132
01133 void IconView::HandleMenuButtonPress(void)
01134 {
01135 UIListBtnTypeItem *item;
01136
01137 if (m_inSubMenu)
01138 item = m_submenuType->GetItemCurrent();
01139 else
01140 item = m_menuType->GetItemCurrent();
01141
01142 if (!item || !item->getData())
01143 return;
01144
01145 MenuAction *act = (MenuAction*) item->getData();
01146 (this->*(*act))();
01147
01148 m_menuType->SetActive(m_inMenu & !m_inSubMenu);
01149 m_submenuType->SetActive(m_inMenu & m_inSubMenu);
01150 }
01151
01152 void IconView::HandleMainMenu(void)
01153 {
01154 if (m_showDevices)
01155 {
01156 QDir d(m_currDir);
01157 if (!d.exists())
01158 m_currDir = m_galleryDir;
01159
01160 LoadDirectory(m_currDir, true);
01161 m_showDevices = false;
01162 }
01163
01164 ClearMenu(m_submenuType);
01165 m_submenuType->Reset();
01166
01167 m_inSubMenu = false;
01168 }
01169
01170 void IconView::HandleSubMenuMetadata(void)
01171 {
01172 ClearMenu(m_submenuType);
01173 m_submenuType->Reset();
01174
01175 UIListBtnTypeItem *item;
01176 item = new UIListBtnTypeItem(m_submenuType, tr("Return"));
01177 item->setData(new MenuAction(&IconView::HandleMainMenu));
01178
01179 item = new UIListBtnTypeItem(m_submenuType, tr("Rotate CW"));
01180 item->setData(new MenuAction(&IconView::HandleRotateCW));
01181
01182 item = new UIListBtnTypeItem(m_submenuType, tr("Rotate CCW"));
01183 item->setData(new MenuAction(&IconView::HandleRotateCCW));
01184
01185 m_inSubMenu = true;
01186 }
01187
01188 void IconView::HandleSubMenuMark(void)
01189 {
01190 ClearMenu(m_submenuType);
01191 m_submenuType->Reset();
01192
01193 UIListBtnTypeItem *item;
01194 item = new UIListBtnTypeItem(m_submenuType, tr("Return"));
01195 item->setData(new MenuAction(&IconView::HandleMainMenu));
01196
01197 item = new UIListBtnTypeItem(m_submenuType, tr("Clear Marked"));
01198 item->setData(new MenuAction(&IconView::HandleClearMarked));
01199
01200 item = new UIListBtnTypeItem(m_submenuType, tr("Select All"));
01201 item->setData(new MenuAction(&IconView::HandleSelectAll));
01202
01203 m_inSubMenu = true;
01204 }
01205
01206 void IconView::HandleSubMenuFile(void)
01207 {
01208 ClearMenu(m_submenuType);
01209 m_submenuType->Reset();
01210
01211 UIListBtnTypeItem *item;
01212 item = new UIListBtnTypeItem(m_submenuType, tr("Return"));
01213 item->setData(new MenuAction(&IconView::HandleMainMenu));
01214
01215 item = new UIListBtnTypeItem(m_submenuType, tr("Show Devices"));
01216 item->setData(new MenuAction(&IconView::HandleShowDevices));
01217
01218 item = new UIListBtnTypeItem(m_submenuType, tr("Eject"));
01219 item->setData(new MenuAction(&IconView::HandleEject));
01220
01221 item = new UIListBtnTypeItem(m_submenuType, tr("Import"));
01222 item->setData(new MenuAction(&IconView::HandleImport));
01223
01224 item = new UIListBtnTypeItem(m_submenuType, tr("Copy here"));
01225 item->setData(new MenuAction(&IconView::HandleCopyHere));
01226
01227 item = new UIListBtnTypeItem(m_submenuType, tr("Move here"));
01228 item->setData(new MenuAction(&IconView::HandleMoveHere));
01229
01230 item = new UIListBtnTypeItem(m_submenuType, tr("Delete"));
01231 item->setData(new MenuAction(&IconView::HandleDelete));
01232
01233 item = new UIListBtnTypeItem(m_submenuType, tr("Create Dir"));
01234 item->setData(new MenuAction(&IconView::HandleMkDir));
01235
01236 item = new UIListBtnTypeItem(m_submenuType, tr("Rename"));
01237 item->setData(new MenuAction(&IconView::HandleRename));
01238
01239 m_inSubMenu = true;
01240 }
01241
01242 void IconView::HandleRotateCW(void)
01243 {
01244 ThumbItem *item = m_itemList.at(m_currRow * m_nCols + m_currCol);
01245 if (!item || item->IsDir())
01246 return;
01247
01248 int rotAngle = item->GetRotationAngle();
01249
01250 rotAngle += 90;
01251
01252 if (rotAngle >= 360)
01253 rotAngle -= 360;
01254
01255 if (rotAngle < 0)
01256 rotAngle += 360;
01257
01258 item->SetRotationAngle(rotAngle);
01259 }
01260
01261 void IconView::HandleRotateCCW(void)
01262 {
01263 ThumbItem *item = m_itemList.at(m_currRow * m_nCols + m_currCol);
01264 if (!item || item->IsDir())
01265 return;
01266
01267 int rotAngle = item->GetRotationAngle();
01268
01269 rotAngle -= 90;
01270
01271 if (rotAngle >= 360)
01272 rotAngle -= 360;
01273
01274 if (rotAngle < 0)
01275 rotAngle += 360;
01276
01277 item->SetRotationAngle(rotAngle);
01278 }
01279
01280 void IconView::HandleDeleteCurrent(void)
01281 {
01282 ThumbItem *item = m_itemList.at(m_currRow * m_nCols + m_currCol);
01283
01284 if (!item)
01285 return;
01286
01287 QString title = tr("Delete Current File or Folder");
01288 QString msg = (item->IsDir()) ?
01289 tr("Deleting 1 folder, including any subfolders and files.") :
01290 tr("Deleting 1 image.");
01291
01292 bool cont = MythPopupBox::showOkCancelPopup(
01293 gContext->GetMainWindow(), title, msg, false);
01294
01295 if (cont)
01296 {
01297 QFileInfo fi;
01298 fi.setFile(item->GetPath());
01299 GalleryUtil::Delete(fi);
01300
01301 LoadDirectory(m_currDir, true);
01302 }
01303 }
01304
01305 void IconView::HandleSettings(void)
01306 {
01307 GallerySettings settings;
01308 settings.exec();
01309 gContext->ClearSettingsCache();
01310
01311
01312 m_showcaption = gContext->GetNumSetting("GalleryOverlayCaption", 0);
01313 m_sortorder = gContext->GetNumSetting("GallerySortOrder", 0);
01314 m_useOpenGL = gContext->GetNumSetting("SlideshowUseOpenGL", 0);
01315 m_recurse = gContext->GetNumSetting("GalleryRecursiveSlideshow", 0);
01316 m_paths = QStringList::split(
01317 ":", gContext->GetSetting("GalleryImportDirs"));
01318
01319
01320 MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
01321 if (m_currDevice && mon && mon->ValidateAndLock(m_currDevice))
01322 {
01323 LoadDirectory(m_currDevice->getMountPath(), true);
01324 mon->Unlock(m_currDevice);
01325 }
01326 else
01327 {
01328 m_currDevice = NULL;
01329 LoadDirectory(m_galleryDir, true);
01330 }
01331 }
01332
01333 void IconView::HandleEject(void)
01334 {
01335 myth_eject();
01336 }
01337
01338 void IconView::HandleImport(void)
01339 {
01340 QFileInfo path;
01341 QDir importdir;
01342
01343 DialogBox *importDlg = new DialogBox(
01344 gContext->GetMainWindow(), tr("Import pictures?"));
01345
01346 importDlg->AddButton(tr("No"));
01347 importDlg->AddButton(tr("Yes"));
01348 DialogCode code = importDlg->exec();
01349 importDlg->deleteLater();
01350 if (kDialogCodeButton1 != code)
01351 return;
01352
01353
01354 QString idirname = m_currDir + "/" +
01355 QDateTime::currentDateTime().toString("yyyy-MM-dd_hh-mm-ss");
01356
01357 importdir.mkdir(idirname);
01358 importdir.setPath(idirname);
01359
01360 for (QStringList::const_iterator it = m_paths.begin();
01361 it != m_paths.end(); ++it)
01362 {
01363 path.setFile(*it);
01364 if (path.isDir() && path.isReadable())
01365 {
01366 ImportFromDir(*it, importdir.absPath());
01367 }
01368 else if (path.isFile() && path.isExecutable())
01369 {
01370
01371 QString cmd = *it + " " + importdir.absPath();
01372 VERBOSE(VB_GENERAL, LOC + QString("Executing %1").arg(cmd));
01373 myth_system(cmd);
01374 }
01375 else
01376 {
01377 VERBOSE(VB_IMPORTANT, LOC_ERR +
01378 QString("Could not read or execute %1").arg(*it));
01379 }
01380 }
01381
01382 #if QT_VERSION >= 0x030100
01383 importdir.refresh();
01384 if (importdir.count() == 0)
01385 #endif
01386
01387 if (importdir.rmdir(importdir.absPath()))
01388 {
01389 DialogBox *nopicsDlg = new DialogBox(
01390 gContext->GetMainWindow(), tr("Nothing found to import"));
01391
01392 nopicsDlg->AddButton(tr("OK"));
01393 nopicsDlg->exec();
01394 nopicsDlg->deleteLater();
01395
01396 return;
01397 }
01398
01399 ThumbItem *item = new ThumbItem(importdir.dirName(),
01400 importdir.absPath(), true);
01401 m_itemList.append(item);
01402 m_itemDict.insert(item->GetName(), item);
01403 m_thumbGen->addFile(item->GetName());
01404
01405 if (!m_thumbGen->running())
01406 {
01407 m_thumbGen->start();
01408 }
01409 }
01410
01411 void IconView::HandleShowDevices(void)
01412 {
01413 #ifndef _WIN32
01414 MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
01415 if (m_currDevice && mon && mon->ValidateAndLock(m_currDevice))
01416 {
01417 m_currDevice->disconnect(this);
01418 mon->Unlock(m_currDevice);
01419 }
01420 else
01421 m_currDir = m_galleryDir;
01422 #endif
01423
01424 m_currDevice = NULL;
01425
01426 m_showDevices = true;
01427
01428 m_itemList.clear();
01429 m_itemDict.clear();
01430
01431 m_thumbGen->cancel();
01432
01433
01434 ThumbItem *item = new ThumbItem("Gallery", m_galleryDir, true);
01435 m_itemList.append(item);
01436 m_itemDict.insert(item->GetName(), item);
01437
01438 #ifndef _WIN32
01439 if (mon)
01440 {
01441 QValueList<MythMediaDevice*> removables =
01442 mon->GetMedias(MEDIATYPE_DATA);
01443 QValueList<MythMediaDevice*>::Iterator it = removables.begin();
01444 for (; it != removables.end(); it++)
01445 {
01446 if (mon->ValidateAndLock(*it))
01447 {
01448 item = new ThumbItem(
01449 (*it)->getVolumeID().isEmpty() ?
01450 (*it)->getDevicePath() : (*it)->getVolumeID(),
01451 (*it)->getMountPath(), true, *it);
01452
01453 m_itemList.append(item);
01454 m_itemDict.insert(item->GetName(), item);
01455
01456 mon->Unlock(*it);
01457 }
01458 }
01459 }
01460 #endif
01461
01462 m_lastRow = QMAX((int)ceilf((float)m_itemList.count()/(float)m_nCols)-1,0);
01463 m_lastCol = QMAX(m_itemList.count()-m_lastRow*m_nCols-1,0);
01464
01465
01466 m_inMenu = false;
01467 update();
01468 }
01469
01470 void IconView::HandleCopyHere(void)
01471 {
01472 CopyMarkedFiles(false);
01473 HandleClearMarked();
01474 }
01475
01476 void IconView::HandleMoveHere(void)
01477 {
01478 CopyMarkedFiles(true);
01479 HandleClearMarked();
01480 }
01481
01482 void IconView::HandleDelete(void)
01483 {
01484 if (m_itemMarked.isEmpty())
01485 HandleDeleteCurrent();
01486 else
01487 HandleDeleteMarked();
01488 }
01489
01490 void IconView::HandleDeleteMarked(void)
01491 {
01492 bool cont = MythPopupBox::showOkCancelPopup(gContext->GetMainWindow(),
01493 tr("Delete Marked Files"),
01494 QString(tr("Deleting %1 images and folders, including "
01495 "any subfolders and files."))
01496 .arg(m_itemMarked.count()),
01497 false);
01498
01499 if (cont)
01500 {
01501 QStringList::iterator it;
01502 QFileInfo fi;
01503
01504 for (it = m_itemMarked.begin(); it != m_itemMarked.end(); it++)
01505 {
01506 fi.setFile(*it);
01507
01508 GalleryUtil::Delete(fi);
01509 }
01510
01511 m_itemMarked.clear();
01512
01513 LoadDirectory(m_currDir, true);
01514 }
01515 }
01516
01517 void IconView::HandleClearMarked(void)
01518 {
01519 m_itemMarked.clear();
01520 }
01521
01522 void IconView::HandleSelectAll(void)
01523 {
01524 ThumbItem *item;
01525 for (item = m_itemList.first(); item; item = m_itemList.next())
01526 {
01527 if (!m_itemMarked.contains(item->GetPath()))
01528 m_itemMarked.append(item->GetPath());
01529 }
01530 }
01531
01532 void IconView::HandleMkDir(void)
01533 {
01534 QString folderName = tr("New Folder");
01535
01536 bool res = MythPopupBox::showGetTextPopup(
01537 gContext->GetMainWindow(), tr("Create New Folder"),
01538 tr("Create New Folder"), folderName);
01539
01540 if (res)
01541 {
01542 QDir cdir(m_currDir);
01543 cdir.mkdir(folderName);
01544
01545 LoadDirectory(m_currDir, true);
01546 }
01547 }
01548
01549
01550 void IconView::HandleRename(void)
01551 {
01552 ThumbItem *item = m_itemList.at(m_currRow * m_nCols + m_currCol);
01553
01554 if (!item)
01555 return;
01556
01557 QString folderName = item->GetName();
01558
01559 bool res = MythPopupBox::showGetTextPopup(
01560 gContext->GetMainWindow(), tr("Rename"),
01561 tr("Rename"), folderName);
01562
01563 if (folderName.isEmpty() || folderName == "." || folderName == "..")
01564 return;
01565
01566 if (res)
01567 {
01568 if (!GalleryUtil::Rename(m_currDir, item->GetName(), folderName))
01569 {
01570 QString msg;
01571 if (item->IsDir())
01572 msg = tr("Failed to rename directory");
01573 else
01574 msg = tr("Failed to rename file");
01575
01576 DialogBox *dlg = new DialogBox(gContext->GetMainWindow(), msg);
01577 dlg->AddButton(tr("OK"));
01578 dlg->exec();
01579 dlg->deleteLater();
01580
01581 return;
01582 }
01583
01584 LoadDirectory(m_currDir, true);
01585 }
01586 }
01587
01588
01589
01590 void IconView::ImportFromDir(const QString &fromDir, const QString &toDir)
01591 {
01592 QDir d(fromDir);
01593
01594 if (!d.exists())
01595 return;
01596
01597 d.setNameFilter(MEDIA_FILENAMES);
01598 d.setSorting(m_sortorder);
01599 d.setFilter(QDir::Files | QDir::Dirs | QDir::NoSymLinks | QDir::Readable);
01600 d.setMatchAllDirs(true);
01601 const QFileInfoList *list = d.entryInfoList();
01602 if (!list)
01603 return;
01604 QFileInfoListIterator it(*list);
01605 QFileInfo *fi;
01606
01607 while ((fi = it.current()) != 0)
01608 {
01609 ++it;
01610 if (fi->fileName() == "." || fi->fileName() == "..")
01611 continue;
01612
01613 if (fi->isDir())
01614 {
01615 QString newdir(toDir + "/" + fi->fileName());
01616 d.mkdir(newdir);
01617 ImportFromDir(fi->absFilePath(), newdir);
01618 }
01619 else
01620 {
01621 VERBOSE(VB_GENERAL, LOC + QString("Copying %1 to %2")
01622 .arg(fi->absFilePath().local8Bit())
01623 .arg(toDir.local8Bit()));
01624
01625
01626 QString cmd = "cp \"" + fi->absFilePath().local8Bit() +
01627 "\" \"" + toDir.local8Bit() + "\"";
01628
01629 myth_system(cmd);
01630 }
01631 }
01632 }
01633
01634 void IconView::CopyMarkedFiles(bool move)
01635 {
01636 if (m_itemMarked.isEmpty())
01637 return;
01638
01639 QStringList::iterator it;
01640 QFileInfo fi;
01641 QFileInfo dest;
01642 int count = 0;
01643
01644 QString msg = (move) ?
01645 tr("Moving marked images...") : tr("Copying marked images...");
01646
01647 MythProgressDialog *progress =
01648 new MythProgressDialog(msg, m_itemMarked.count());
01649
01650 for (it = m_itemMarked.begin(); it != m_itemMarked.end(); it++)
01651 {
01652 fi.setFile(*it);
01653 dest.setFile(QDir(m_currDir), fi.fileName());
01654
01655 if (fi.exists())
01656 GalleryUtil::CopyMove(fi, dest, move);
01657
01658 progress->setProgress(++count);
01659 }
01660
01661 progress->Close();
01662 progress->deleteLater();
01663
01664 LoadDirectory(m_currDir, true);
01665 }
01666
01667 void IconView::ClearMenu(UIListBtnType *menu)
01668 {
01669 if (!menu)
01670 return;
01671
01672 UIListBtnTypeItem *item = menu->GetItemFirst();
01673 while (item)
01674 {
01675 MenuAction *act = (MenuAction*) item->getData();
01676 if (act)
01677 delete act;
01678 item = menu->GetItemNext(item);
01679 }
01680 }
01681
01682 void IconView::mediaStatusChanged(MediaStatus oldStatus,
01683 MythMediaDevice *pMedia)
01684 {
01685 (void) oldStatus;
01686 if (m_currDevice == pMedia)
01687 {
01688 HandleShowDevices();
01689
01690 m_currRow = 0;
01691 m_currCol = 0;
01692
01693 UpdateView();
01694 UpdateText();
01695 }
01696 }