Ticket #603: gallery_removable.diff
File gallery_removable.diff, 31.1 KB (added by , 18 years ago) |
---|
-
mythgallery/mythgallery/galleryutil.h
32 32 static bool loadDirectory(ThumbList& itemList, 33 33 const QString& dir, bool recurse, 34 34 ThumbDict *itemDict, ThumbGenerator* thumbGen); 35 36 static QFileInfo copyFile(QFileInfo src, QFileInfo dest, bool move); 37 static bool deleteFile(QFileInfo file); 38 static QFileInfo copyDirectory(QFileInfo src, QFileInfo dest, bool move); 39 static bool deleteDirectory(QFileInfo dir); 35 40 }; 36 41 37 42 #endif /* EXIFUTIL_H */ -
mythgallery/mythgallery/iconview.cpp
31 31 #include <mythtv/xmlparse.h> 32 32 #include <mythtv/dialogbox.h> 33 33 #include <mythtv/mythdbcon.h> 34 #include <mythtv/mythmediamonitor.h> 35 #include <mythtv/mythdialogs.h> 34 36 35 37 #include "galleryutil.h" 36 38 #include "gallerysettings.h" … … 72 74 query.exec(); 73 75 } 74 76 75 IconView::IconView(const QString& galleryDir, MythM ainWindow* parent,76 const char* name )77 IconView::IconView(const QString& galleryDir, MythMediaDevice *initialDevice, 78 MythMainWindow* parent, const char* name ) 77 79 : MythDialog(parent, name) 78 80 { 79 81 m_galleryDir = galleryDir; 80 82 81 83 m_inMenu = false; 84 m_inSubMenu = false; 82 85 m_itemList.setAutoDelete(true); 83 86 m_itemDict.setAutoDelete(false); 84 87 … … 94 97 m_lastCol = 0; 95 98 m_topRow = 0; 96 99 m_isGallery = false; 100 #ifndef _WIN32 101 m_showDevices = false; 102 m_currDevice = initialDevice; 103 #endif 97 104 98 loadDirectory(galleryDir); 105 #ifndef _WIN32 106 if (m_currDevice) 107 { 108 if (!m_currDevice->isMounted(true)) 109 m_currDevice->mount(); 110 111 connect(m_currDevice, SIGNAL(statusChanged(MediaStatus, MythMediaDevice*)), 112 SLOT(mediaStatusChanged(MediaStatus, MythMediaDevice*))); 113 114 loadDirectory(m_currDevice->getMountPath()); 115 } 116 else 117 #endif 118 loadDirectory(galleryDir); 99 119 } 100 120 101 121 IconView::~IconView() 102 122 { 103 UIListBtnTypeItem* item = m_menuType->GetItemFirst(); 104 while (item) { 105 Action *act = (Action*) item->getData(); 106 if (act) 107 delete act; 108 item = m_menuType->GetItemNext(item); 109 } 110 123 clearMenu(m_submenuType); 124 clearMenu(m_menuType); 125 111 126 delete m_thumbGen; 112 127 delete m_theme; 113 128 } … … 232 247 item->pixmap->height()/2-bh2+sh, 233 248 bw-2*sw, bh-2*sh-(int)(15*hmult)); 234 249 250 if (m_itemMarked.contains(item->path)) 251 { 252 p.drawPixmap(xpos, ypos, m_MrkPix); 253 } 254 235 255 } 236 256 else { 237 257 … … 246 266 item->pixmap->width()/2-bw2+sw, 247 267 item->pixmap->height()/2-bh2+sh, 248 268 bw-2*sw, bh-2*sh); 269 270 if (m_itemMarked.contains(item->path)) 271 { 272 p.drawPixmap(xpos, ypos, m_MrkPix); 273 } 249 274 } 250 275 251 276 curPos++; … … 273 298 QString action = actions[i]; 274 299 if (action == "MENU") { 275 300 m_inMenu = !m_inMenu; 276 m_menuType->SetActive(m_inMenu); 301 m_menuType->SetActive(m_inMenu & !m_inSubMenu); 302 m_submenuType->SetActive(m_inMenu & m_inSubMenu); 277 303 menuHandled = true; 278 304 } 279 305 else if (action == "UP") { 280 if (m_inMenu ) {306 if (m_inMenu & !m_inSubMenu) { 281 307 m_menuType->MoveUp(); 282 308 menuHandled = true; 283 309 } 310 else if (m_inMenu & m_inSubMenu) { 311 m_submenuType->MoveUp(); 312 menuHandled = true; 313 } 284 314 else 285 315 handled = moveUp(); 286 316 } 287 317 else if (action == "DOWN") { 288 if (m_inMenu ) {318 if (m_inMenu & !m_inSubMenu) { 289 319 m_menuType->MoveDown(); 290 320 menuHandled = true; 291 321 } 322 else if (m_inMenu & m_inSubMenu) { 323 m_submenuType->MoveDown(); 324 menuHandled = true; 325 } 292 326 else 293 327 handled = moveDown(); 294 328 } … … 322 356 m_topRow = QMAX(m_currRow-(m_nRows-1),0); 323 357 handled = true; 324 358 } 359 else if (action == "MARK") 360 { 361 int pos = m_currRow * m_nCols + m_currCol; 362 ThumbItem *item = m_itemList.at(pos); 363 if (!item) { 364 std::cerr << "The impossible happened" << std::endl; 365 break; 366 } 367 368 std::cout << "(un)marking " << item->path.ascii() << std::endl; 369 370 if (!m_itemMarked.contains(item->path)) 371 m_itemMarked.append(item->path); 372 else 373 m_itemMarked.remove(item->path); 374 375 handled = true; 376 } 325 377 else if (action == "SELECT" || action == "PLAY") 326 378 { 327 379 if (m_inMenu) { … … 337 389 } 338 390 339 391 QFileInfo fi(item->path); 392 #ifndef _WIN32 393 if (item->mediaDevice) 394 { 395 m_currDevice = item->mediaDevice; 396 397 if (!m_currDevice->isMounted()) 398 m_currDevice->mount(); 399 400 item->path = m_currDevice->getMountPath(); 401 402 connect(m_currDevice, SIGNAL(statusChanged(MediaStatus, MythMediaDevice*)), 403 SLOT(mediaStatusChanged(MediaStatus, MythMediaDevice*))); 404 } 405 #endif 340 406 if (item->isDir) { 341 407 loadDirectory(item->path); 342 408 handled = true; … … 380 446 { 381 447 QString action = actions[i]; 382 448 if (action == "ESCAPE") { 383 QDir d(m_currDir); 384 if (d != QDir(m_galleryDir)) { 449 #ifndef _WIN32 450 if (m_showDevices) 451 { 452 loadDirectory(m_galleryDir); 453 handled = true; 454 } 455 else 456 { 457 #endif 458 QDir d(m_currDir); 459 #ifndef _WIN32 460 MediaMonitor *mon = MediaMonitor::getMediaMonitor(); 461 if (mon) 462 { 463 QValueList <MythMediaDevice *> removables = mon->getMedias(MEDIATYPE_DATA); 464 QValueList <MythMediaDevice *>::Iterator it = removables.begin(); 465 for (; it != removables.end(); it++) 466 { 467 if (d == QDir((*it)->getMountPath())) 468 { 469 actionShowDevices(); 385 470 386 QString oldDirName = d.dirName(); 387 d.cdUp(); 388 loadDirectory(d.absPath()); 471 // make sure previous devies is visible and selected 472 ThumbItem *item; 473 if ((*it)->getVolumeID() != "") 474 item = m_itemDict.find((*it)->getVolumeID()); 475 else 476 item = m_itemDict.find((*it)->getDevicePath()); 389 477 390 // make sure up-directory is visible and selected 391 ThumbItem* item = m_itemDict.find(oldDirName); 392 if (item) { 393 int pos = m_itemList.find(item); 394 if (pos != -1) { 395 m_currRow = pos/m_nCols; 396 m_currCol = pos-m_currRow*m_nCols; 397 m_topRow = QMAX(0, m_currRow-(m_nRows-1)); 478 if (item) 479 { 480 int pos = m_itemList.find(item); 481 if (pos != -1) 482 { 483 m_currRow = pos/m_nCols; 484 m_currCol = pos-m_currRow*m_nCols; 485 m_topRow = QMAX(0, m_currRow-(m_nRows-1)); 486 } 487 } 488 handled = true; 489 break; 490 } 398 491 } 399 492 } 400 handled = true; 493 if (!handled) 494 { 495 #endif 496 if (d != QDir(m_galleryDir)) { 497 498 QString oldDirName = d.dirName(); 499 d.cdUp(); 500 loadDirectory(d.absPath()); 501 502 // make sure up-directory is visible and selected 503 ThumbItem* item = m_itemDict.find(oldDirName); 504 if (item) { 505 int pos = m_itemList.find(item); 506 if (pos != -1) { 507 m_currRow = pos/m_nCols; 508 m_currCol = pos-m_currRow*m_nCols; 509 m_topRow = QMAX(0, m_currRow-(m_nRows-1)); 510 } 511 } 512 handled = true; 513 } 514 #ifndef _WIN32 515 } 401 516 } 517 #endif 402 518 } 403 519 } 404 520 } … … 501 617 exit(-1); 502 618 } 503 619 620 m_submenuType = (UIListBtnType*)container->GetType("submenu"); 621 if (!m_menuType) { 622 std::cerr << "MythGallery: Failed to get submenu area." 623 << std::endl; 624 exit(-1); 625 } 626 504 627 // Menu Actions 505 628 506 629 UIListBtnTypeItem* item; … … 508 631 item->setData(new Action(&IconView::actionSlideShow)); 509 632 item = new UIListBtnTypeItem(m_menuType, tr("Random")); 510 633 item->setData(new Action(&IconView::actionRandomShow)); 511 item = new UIListBtnTypeItem(m_menuType, tr(" Rotate CW"));512 item->setData(new Action(&IconView::action RotateCW));513 item = new UIListBtnTypeItem(m_menuType, tr(" Rotate CCW"));514 item->setData(new Action(&IconView::action RotateCCW));515 item = new UIListBtnTypeItem(m_menuType, tr(" Import"));516 item->setData(new Action(&IconView::action Import));634 item = new UIListBtnTypeItem(m_menuType, tr("Meta Data...")); 635 item->setData(new Action(&IconView::actionSubMenuMetadata)); 636 item = new UIListBtnTypeItem(m_menuType, tr("Marking...")); 637 item->setData(new Action(&IconView::actionSubMenuMark)); 638 item = new UIListBtnTypeItem(m_menuType, tr("File...")); 639 item->setData(new Action(&IconView::actionSubMenuFile)); 517 640 item = new UIListBtnTypeItem(m_menuType, tr("Settings")); 518 641 item->setData(new Action(&IconView::actionSettings)); 519 642 520 643 m_menuType->SetActive(false); 521 644 522 645 container = m_theme->GetSet("view"); … … 570 693 m_folderSelPix = QPixmap(*img); 571 694 delete img; 572 695 696 img = gContext->LoadScaleImage("gallery-mark.png"); 697 if (!img) { 698 std::cerr << "Failed to load gallery-mark.png" 699 << std::endl; 700 exit(-1); 701 } 702 m_MrkPix = QPixmap(*img); 703 delete img; 704 573 705 m_thumbW = m_backRegPix.width(); 574 706 m_thumbH = m_backRegPix.height(); 575 707 m_nCols = m_viewRect.width()/m_thumbW - 1; … … 586 718 if (!d.exists()) 587 719 return; 588 720 721 #ifndef _WIN32 722 m_showDevices = false; 723 #endif 724 589 725 m_currDir = d.absPath(); 590 726 m_itemList.clear(); 591 727 m_itemDict.clear(); … … 718 854 719 855 void IconView::pressMenu() 720 856 { 721 UIListBtnTypeItem* item = m_menuType->GetItemCurrent();857 UIListBtnTypeItem* item; 722 858 859 if (m_inSubMenu) 860 item = m_submenuType->GetItemCurrent(); 861 else 862 item = m_menuType->GetItemCurrent(); 863 723 864 if (!item || !item->getData()) 724 865 return; 725 866 726 867 Action *act = (Action*) item->getData(); 727 868 (this->*(*act))(); 869 870 m_menuType->SetActive(m_inMenu & !m_inSubMenu); 871 m_submenuType->SetActive(m_inMenu & m_inSubMenu); 728 872 } 729 873 874 void IconView::actionMainMenu() 875 { 876 clearMenu(m_submenuType); 877 m_submenuType->Reset(); 878 879 m_inSubMenu = false; 880 } 881 882 void IconView::actionSubMenuMetadata() 883 { 884 clearMenu(m_submenuType); 885 m_submenuType->Reset(); 886 887 UIListBtnTypeItem *item; 888 item = new UIListBtnTypeItem(m_submenuType, tr("Return")); 889 item->setData(new Action(&IconView::actionMainMenu)); 890 item = new UIListBtnTypeItem(m_submenuType, tr("Rotate CW")); 891 item->setData(new Action(&IconView::actionRotateCW)); 892 item = new UIListBtnTypeItem(m_submenuType, tr("Rotate CCW")); 893 item->setData(new Action(&IconView::actionRotateCCW)); 894 895 m_inSubMenu = true; 896 } 897 898 void IconView::actionSubMenuMark() 899 { 900 clearMenu(m_submenuType); 901 m_submenuType->Reset(); 902 903 UIListBtnTypeItem *item; 904 item = new UIListBtnTypeItem(m_submenuType, tr("Return")); 905 item->setData(new Action(&IconView::actionMainMenu)); 906 item = new UIListBtnTypeItem(m_submenuType, tr("Clear Marked")); 907 item->setData(new Action(&IconView::actionClearMarked)); 908 item = new UIListBtnTypeItem(m_submenuType, tr("Select All")); 909 item->setData(new Action(&IconView::actionSelectAll)); 910 911 m_inSubMenu = true; 912 } 913 914 void IconView::actionSubMenuFile() 915 { 916 clearMenu(m_submenuType); 917 m_submenuType->Reset(); 918 919 UIListBtnTypeItem *item; 920 item = new UIListBtnTypeItem(m_submenuType, tr("Return")); 921 item->setData(new Action(&IconView::actionMainMenu)); 922 #ifndef _WIN32 923 item = new UIListBtnTypeItem(m_submenuType, tr("Show Devices")); 924 item->setData(new Action(&IconView::actionShowDevices)); 925 #endif 926 item = new UIListBtnTypeItem(m_submenuType, tr("Import")); 927 item->setData(new Action(&IconView::actionImport)); 928 item = new UIListBtnTypeItem(m_submenuType, tr("Copy here")); 929 item->setData(new Action(&IconView::actionCopyHere)); 930 item = new UIListBtnTypeItem(m_submenuType, tr("Move here")); 931 item->setData(new Action(&IconView::actionMoveHere)); 932 item = new UIListBtnTypeItem(m_submenuType, tr("Delete Marked")); 933 item->setData(new Action(&IconView::actionDeleteMarked)); 934 item = new UIListBtnTypeItem(m_submenuType, tr("Create Dir")); 935 item->setData(new Action(&IconView::actionMkDir)); 936 937 m_inSubMenu = true; 938 } 939 730 940 void IconView::actionRotateCW() 731 941 { 732 942 ThumbItem* item = m_itemList.at(m_currRow * m_nCols + … … 908 1118 } 909 1119 } 910 1120 1121 #ifndef _WIN32 1122 void IconView::actionShowDevices() 1123 { 1124 if (m_currDevice) 1125 { 1126 m_currDevice->disconnect(this); 1127 m_currDevice = NULL; 1128 } 1129 1130 m_showDevices = true; 1131 1132 m_itemList.clear(); 1133 m_itemDict.clear(); 1134 1135 m_thumbGen->cancel(); 1136 1137 /* add gallery directory */ 1138 ThumbItem *item = new ThumbItem; 1139 item->name = QString("Gallery"); 1140 item->path = m_galleryDir; 1141 item->isDir = true; 1142 m_itemList.append(item); 1143 m_itemDict.insert(item->name, item); 1144 1145 MediaMonitor *mon = MediaMonitor::getMediaMonitor(); 1146 if (mon) 1147 { 1148 QValueList <MythMediaDevice *> removables = mon->getMedias(MEDIATYPE_DATA); 1149 QValueList <MythMediaDevice *>::Iterator it = removables.begin(); 1150 for (; it != removables.end(); it++) 1151 { 1152 item = new ThumbItem; 1153 if ((*it)->getVolumeID() != "") 1154 item->name = (*it)->getVolumeID(); 1155 else 1156 item->name = (*it)->getDevicePath(); 1157 item->path = (*it)->getMountPath(); 1158 item->isDir = true; 1159 item->mediaDevice = *it; 1160 m_itemList.append(item); 1161 m_itemDict.insert(item->name, item); 1162 } 1163 } 1164 1165 m_lastRow = QMAX((int)ceilf((float)m_itemList.count()/(float)m_nCols)-1,0); 1166 m_lastCol = QMAX(m_itemList.count()-m_lastRow*m_nCols-1,0); 1167 } 1168 #endif 1169 1170 void IconView::actionCopyHere() 1171 { 1172 copyMarkedFiles(false); 1173 } 1174 1175 void IconView::actionMoveHere() 1176 { 1177 copyMarkedFiles(true); 1178 } 1179 1180 void IconView::actionDeleteMarked() 1181 { 1182 std::cerr << "deleting marked files\n"; 1183 1184 bool cont = MythPopupBox::showOkCancelPopup(gContext->GetMainWindow(), tr("Delete Marked Files"), 1185 QString(tr("Deleting %1 images and folders")) 1186 .arg(m_itemMarked.count()), false); 1187 1188 if (cont) 1189 { 1190 QStringList::iterator it; 1191 QFileInfo fi; 1192 1193 for (it = m_itemMarked.begin(); it != m_itemMarked.end(); it++) 1194 { 1195 fi.setFile(*it); 1196 1197 std::cerr << "fi = " << fi.absFilePath() << endl; 1198 1199 if (fi.exists()) 1200 { 1201 if (fi.isDir()) 1202 { 1203 GalleryUtil::deleteDirectory(fi); 1204 std::cerr << "deleting directory " << fi.absFilePath().local8Bit() << endl; 1205 } 1206 else 1207 { 1208 GalleryUtil::deleteFile(fi); 1209 std::cerr << "deleting file " << fi.absFilePath().local8Bit() << endl; 1210 } 1211 } 1212 } 1213 1214 m_itemMarked.clear(); 1215 1216 loadDirectory(m_currDir); 1217 } 1218 } 1219 1220 void IconView::actionClearMarked() 1221 { 1222 m_itemMarked.clear(); 1223 } 1224 1225 void IconView::actionSelectAll() 1226 { 1227 ThumbItem *item; 1228 for (item = m_itemList.first(); item; item = m_itemList.next()) 1229 { 1230 if (!m_itemMarked.contains(item->path)) 1231 m_itemMarked.append(item->path); 1232 } 1233 } 1234 1235 void IconView::actionMkDir() 1236 { 1237 QString folderName = tr("New Folder"); 1238 1239 bool res = MythPopupBox::showGetTextPopup(gContext->GetMainWindow(), tr("Create New Folder"), 1240 tr("Create New Folder"), folderName); 1241 1242 if (res) 1243 { 1244 QDir cdir(m_currDir); 1245 cdir.mkdir(folderName); 1246 1247 loadDirectory(m_currDir); 1248 } 1249 } 1250 911 1251 void IconView::importFromDir(const QString &fromDir, const QString &toDir) 912 1252 { 913 1253 QDir d(fromDir); … … 947 1287 } 948 1288 } 949 1289 } 1290 1291 void IconView::copyMarkedFiles(bool move) 1292 { 1293 QStringList::iterator it; 1294 QFileInfo fi; 1295 QFileInfo dest; 1296 1297 for (it = m_itemMarked.begin(); it != m_itemMarked.end(); it++) 1298 { 1299 fi.setFile(*it); 1300 dest.setFile(QDir(m_currDir), fi.fileName()); 1301 1302 if (fi.exists()) 1303 { 1304 if (fi.isDir()) 1305 dest = GalleryUtil::copyDirectory(fi, dest, move); 1306 else 1307 dest = GalleryUtil::copyFile(fi, dest, move); 1308 1309 *it = dest.absFilePath(); 1310 } 1311 } 1312 1313 loadDirectory(m_currDir); 1314 } 1315 1316 void IconView::clearMenu(UIListBtnType *menu) 1317 { 1318 UIListBtnTypeItem* item = menu->GetItemFirst(); 1319 while (item) 1320 { 1321 Action *act = (Action*) item->getData(); 1322 if (act) 1323 delete act; 1324 item = menu->GetItemNext(item); 1325 } 1326 } 1327 1328 void IconView::mediaStatusChanged( MediaStatus oldStatus, MythMediaDevice* pMedia) 1329 { 1330 if (m_currDevice == pMedia) 1331 { 1332 actionShowDevices(); 1333 1334 m_currRow = 0; 1335 m_currCol = 0; 1336 1337 updateView(); 1338 updateText(); 1339 } 1340 } -
mythgallery/mythgallery/main.cpp
14 14 #include <mythtv/mythdialogs.h> 15 15 #include <mythtv/mythplugin.h> 16 16 #include <mythtv/dialogbox.h> 17 #include <mythtv/mythmedia.h> 17 18 18 19 extern "C" { 19 20 int mythplugin_init(const char *libversion); … … 33 34 diag.exec(); 34 35 } 35 36 else { 36 IconView icv(startdir, gContext->GetMainWindow(), "IconView");37 IconView icv(startdir, NULL, gContext->GetMainWindow(), "IconView"); 37 38 icv.exec(); 38 39 } 39 40 } 40 41 42 void handleMedia(MythMediaDevice *dev) 43 { 44 QString galleryDir = gContext->GetSetting("GalleryDir"); 45 QDir dir(galleryDir); 46 if (!dir.exists() || !dir.isReadable()) { 47 DialogBox diag(gContext->GetMainWindow(), 48 QObject::tr("Gallery Directory does not exist" 49 " or is unreadable.")); 50 diag.AddButton(QObject::tr("Ok")); 51 diag.exec(); 52 } 53 else { 54 IconView icv(galleryDir, dev, gContext->GetMainWindow(), "IconView"); 55 icv.exec(); 56 } 57 } 58 41 59 void setupKeys(void) 42 60 { 43 61 REG_JUMP("MythGallery", "Image viewer / slideshow", "", runGallery); … … 63 81 REG_KEY("Gallery", "LOWRIGHT", "Go to the lower-right corner of the image", 64 82 "PgDown"); 65 83 REG_KEY("Gallery", "INFO", "Toggle Showing Information about Image", "I"); 84 REG_KEY("Gallery", "MARK", "Mark image", "T"); 85 86 REG_MEDIA_HANDLER("MythGallery Media Handler", "", "", handleMedia, MEDIATYPE_DATA | MEDIATYPE_MIXED); 66 87 } 67 88 68 89 int mythplugin_init(const char *libversion) -
mythgallery/mythgallery/thumbgenerator.cpp
280 280 281 281 QString ThumbGenerator::getThumbcacheDir(const QString& inDir) 282 282 { 283 QString galleryDir = gContext->GetSetting("GalleryDir"); 284 283 285 // For directory "/my/images/january", this function either returns 284 286 // "/my/images/january/.thumbcache" or "~/.mythtv/mythgallery/january/.thumbcache" 285 287 QString aPath = inDir + QString("/.thumbcache/"); 286 288 if ( gContext->GetNumSetting("GalleryThumbnailLocation") 287 && ! QDir(aPath).exists() )289 && ! QDir(aPath).exists() && inDir.startsWith(galleryDir)) 288 290 { 289 291 mkpath(aPath); 290 292 } 291 if ( ! gContext->GetNumSetting("GalleryThumbnailLocation") || ! QDir(aPath).exists() )293 if ( ! gContext->GetNumSetting("GalleryThumbnailLocation") || ! QDir(aPath).exists() || ! inDir.startsWith(galleryDir)) 292 294 { 293 295 // Arrive here if storing thumbs in home dir, 294 296 // OR failed to create thumb dir in gallery pics location -
mythgallery/mythgallery/iconview.h
26 26 #include <qpixmap.h> 27 27 28 28 #include <mythtv/mythdialogs.h> 29 #include <mythtv/mythmedia.h> 29 30 30 31 class XMLParse; 31 32 class UIListBtnType; … … 41 42 name = ""; 42 43 path = ""; 43 44 isDir = false; 45 mediaDevice = NULL; 44 46 } 45 47 46 48 ~ThumbItem() { … … 55 57 QString name; 56 58 QString path; 57 59 bool isDir; 60 MythMediaDevice *mediaDevice; 58 61 }; 59 62 60 63 typedef QPtrList<ThumbItem> ThumbList; … … 66 69 67 70 public: 68 71 69 IconView(const QString& galleryDir, MythM ainWindow* parent,70 const char* name = 0);72 IconView(const QString& galleryDir, MythMediaDevice *initialDevice, 73 MythMainWindow* parent, const char* name = 0); 71 74 ~IconView(); 72 75 73 76 protected: … … 90 93 bool moveLeft(); 91 94 bool moveRight(); 92 95 96 void actionMainMenu(); 97 void actionSubMenuMetadata(); 98 void actionSubMenuMark(); 99 void actionSubMenuFile(); 100 93 101 void actionRotateCW(); 94 102 void actionRotateCCW(); 95 103 void actionSlideShow(); 96 104 void actionRandomShow(); 97 105 void actionSettings(); 98 106 void actionImport(); 107 #ifndef _WIN32 108 void actionShowDevices(); 109 #endif 110 void actionCopyHere(); 111 void actionMoveHere(); 112 void actionDeleteMarked(); 113 void actionClearMarked(); 114 void actionSelectAll(); 115 void actionMkDir(); 99 116 117 100 118 void pressMenu(); 101 119 102 120 void loadThumbnail(ThumbItem *item); 103 121 void importFromDir(const QString &fromDir, const QString &toDir); 122 void copyMarkedFiles(bool move = false); 123 124 void clearMenu(UIListBtnType *menu); 104 125 105 126 QPtrList<ThumbItem> m_itemList; 106 127 QDict<ThumbItem> m_itemDict; 128 QStringList m_itemMarked; 107 129 QString m_galleryDir; 108 130 109 131 XMLParse *m_theme; … … 112 134 QRect m_viewRect; 113 135 114 136 bool m_inMenu; 137 bool m_inSubMenu; 115 138 UIListBtnType *m_menuType; 139 UIListBtnType *m_submenuType; 116 140 117 141 QPixmap m_backRegPix; 118 142 QPixmap m_backSelPix; 119 143 QPixmap m_folderRegPix; 120 144 QPixmap m_folderSelPix; 145 QPixmap m_MrkPix; 121 146 122 147 QString m_currDir; 123 148 bool m_isGallery; 149 #ifndef _WIN32 150 bool m_showDevices; 151 MythMediaDevice *m_currDevice; 152 #endif 124 153 125 154 int m_currRow; 126 155 int m_currCol; … … 138 167 ThumbGenerator *m_thumbGen; 139 168 140 169 typedef void (IconView::*Action)(); 170 171 #ifndef _WIN32 172 public slots: 173 void mediaStatusChanged( MediaStatus oldStatus, MythMediaDevice* pMedia); 174 #endif 141 175 }; 142 176 143 177 -
mythgallery/mythgallery/gallery-ui.xml
21 21 </font> 22 22 23 23 <container name="menu"> 24 <area>20,20,140, 240</area>24 <area>20,20,140,500</area> 25 25 26 26 <listbtnarea name="menu" draworder="0"> 27 27 <area>0,0,140,240</area> … … 35 35 <showscrollarrows>no</showscrollarrows> 36 36 </listbtnarea> 37 37 38 <listbtnarea name="submenu" draworder="0"> 39 <area>0,260,140,240</area> 40 <gradient type="unselected" start="#000000" end="#505050" alpha="100"> 41 </gradient> 42 <gradient type="selected" start="#52CA38" end="#349838" alpha="255"> 43 </gradient> 44 <fcnfont name="active" function="active"></fcnfont> 45 <fcnfont name="inactive" function="inactive"></fcnfont> 46 <showarrow>no</showarrow> 47 <showscrollarrows>no</showscrollarrows> 48 </listbtnarea> 49 38 50 </container> 39 51 40 52 <container name="text"> -
mythgallery/mythgallery/galleryutil.cpp
20 20 #include <qfileinfo.h> 21 21 #include <qdir.h> 22 22 23 #include <mythtv/mythdbcon.h> 24 23 25 #include "config.h" 24 26 #include "constants.h" 25 27 #include "galleryutil.h" … … 201 203 202 204 return isGallery; 203 205 } 206 207 QFileInfo GalleryUtil::copyFile(QFileInfo src, QFileInfo dest, bool move) 208 { 209 QFileInfo newDest = dest; 210 211 // test if dest exists 212 int i = 0; 213 while (newDest.exists()) 214 { 215 std::cerr << "need to find a new name for " << dest.absFilePath().local8Bit() << " trying "; 216 newDest.setFile(dest.dir(), dest.baseName() + "_" + QString::number(i) + "." + dest.extension()); 217 std::cerr << newDest.absFilePath().local8Bit() << endl; 218 i++; 219 } 220 221 MSqlQuery query(MSqlQuery::InitCon()); 222 QString cmd; 223 if (move) 224 { 225 std::cerr << "moving " << src.absFilePath().local8Bit(); 226 cmd = "mv "; 227 query.prepare("UPDATE gallerymetadata SET image = :IMAGENEW " 228 "WHERE image = :IMAGEOLD ;"); 229 } 230 else 231 { 232 std::cerr << "copying " << src.absFilePath().local8Bit(); 233 cmd = "cp "; 234 query.prepare("INSERT INTO gallerymetadata (image, keywords, angle) " 235 "SELECT :IMAGENEW , keywords, angle " 236 "FROM gallerymetadata " 237 "WHERE image = :IMAGEOLD ;"); 238 } 239 std::cerr << " to " << newDest.absFilePath().local8Bit() << endl; 240 241 cmd += "\"" + src.absFilePath().local8Bit() + "\" \"" + newDest.absFilePath().local8Bit() + "\""; 242 myth_system(cmd); 243 244 /* update metadata table */ 245 query.bindValue(":IMAGENEW", newDest.absFilePath().utf8()); 246 query.bindValue(":IMAGEOLD", src.absFilePath().utf8()); 247 query.exec(); 248 249 return newDest; 250 } 251 252 bool GalleryUtil::deleteFile(QFileInfo file) 253 { 254 QString cmd = "rm \"" + file.absFilePath().local8Bit() + "\""; 255 myth_system(cmd); 256 257 MSqlQuery query(MSqlQuery::InitCon()); 258 query.prepare("DELETE FROM gallerymetadata " 259 "WHERE image = :IMAGE ;"); 260 query.bindValue(":IMAGE", file.absFilePath().utf8()); 261 query.exec(); 262 263 return true; 264 } 265 266 QFileInfo GalleryUtil::copyDirectory(QFileInfo src, QFileInfo dest, bool move) 267 { 268 QFileInfo newDest = dest; 269 270 QDir srcDir(src.absFilePath()); 271 srcDir.setNameFilter(MEDIA_FILENAMES); 272 srcDir.setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase); 273 srcDir.setMatchAllDirs(true); 274 275 /* test if dest exists and is a directory */ 276 int i = 0; 277 while (newDest.exists() && !newDest.isDir()) 278 { 279 std::cerr << "file exists, but we want dir for " << newDest.absFilePath().local8Bit(); 280 newDest.setFile(dest.absFilePath() + "_" + QString::number(i)); 281 std::cerr << " trying " << newDest.absFilePath().local8Bit() << endl; 282 i++; 283 } 284 285 if (!newDest.exists()) 286 { 287 std::cerr << "creating directory " << newDest.absFilePath().local8Bit() << endl; 288 289 srcDir.mkdir(newDest.absFilePath()); 290 newDest.refresh(); 291 } 292 293 if (newDest.exists() && newDest.isDir()) 294 { 295 QDir dstDir(newDest.absFilePath()); 296 297 const QFileInfoList *list = srcDir.entryInfoList(); 298 299 QFileInfoListIterator it(*list); 300 QFileInfo *fi; 301 QFileInfo dfi; 302 303 while ((fi = it.current()) != 0) 304 { 305 ++it; 306 if (fi->fileName() == "." || fi->fileName() == "..") 307 continue; 308 309 dfi.setFile(dstDir, fi->fileName()); 310 311 std::cerr << "source is " << fi->absFilePath().local8Bit() << endl; 312 std::cerr << "destin is " << dfi.absFilePath().local8Bit() << endl; 313 314 if (fi->isDir()) 315 dfi = copyDirectory(*fi, dfi, move); 316 else 317 dfi = copyFile(*fi, dfi, move); 318 } 319 320 if (move) 321 srcDir.rmdir(src.absFilePath()); 322 } 323 324 return newDest; 325 } 326 327 bool GalleryUtil::deleteDirectory(QFileInfo dir) 328 { 329 QDir srcDir(dir.absFilePath()); 330 srcDir.setNameFilter(MEDIA_FILENAMES); 331 srcDir.setSorting(QDir::Name | QDir::DirsFirst | QDir::IgnoreCase); 332 srcDir.setMatchAllDirs(true); 333 334 if (srcDir.exists()) 335 { 336 const QFileInfoList *list = srcDir.entryInfoList(); 337 338 QFileInfoListIterator it(*list); 339 QFileInfo *fi; 340 341 while ((fi = it.current()) != 0) 342 { 343 ++it; 344 if (fi->fileName() == "." || fi->fileName() == "..") 345 continue; 346 347 if (fi->isDir()) 348 deleteDirectory(*fi); 349 else 350 deleteFile(*fi); 351 } 352 } 353 354 // delete .thumbcache 355 QString cmd = "rm -rf \"" + srcDir.absPath().local8Bit() + "/.thumbcache\""; 356 myth_system(cmd); 357 358 srcDir.rmdir(srcDir.absPath()); 359 360 return true; 361 }