Ticket #8892: 8892-v2.patch
| File 8892-v2.patch, 6.7 KB (added by , 16 years ago) |
|---|
-
programs/mythfrontend/playbackbox.cpp
784 784 785 785 item->DisplayState(rating, "ratingstate"); 786 786 787 QString oldimgfile = item->GetImage("preview"); 787 // If there is no preview image, load it. 788 QString oldimgfile = GetLoadedPreview(*pginfo); 788 789 if (oldimgfile.isEmpty() || force_preview_reload) 789 790 m_preview_tokens.insert(m_helper.GetPreviewImage(*pginfo)); 791 // Try to set preview image 792 if (oldimgfile.isEmpty()) 793 oldimgfile = GetStalePreview(*pginfo); 794 if (item->GetImage("preview").isEmpty()) 795 { 796 if (!oldimgfile.isEmpty()) 797 item->SetImage(oldimgfile, "preview", false); 798 } 790 799 791 800 if ((GetFocusWidget() == m_recordingList) && is_sel) 792 801 { … … 810 819 if (m_previewImage) 811 820 { 812 821 m_previewImage->SetFilename(oldimgfile); 813 m_previewImage->Load( true, true);822 m_previewImage->Load(false, false); 814 823 } 815 824 816 825 // Handle artwork … … 849 858 void PlaybackBox::ItemVisible(MythUIButtonListItem *item) 850 859 { 851 860 ProgramInfo *pginfo = qVariantValue<ProgramInfo*>(item->GetData()); 861 if (!pginfo) 862 return; 852 863 853 864 // Job status (recording, transcoding, flagging) 854 865 QString job = extract_job_state(*pginfo); 855 866 item->DisplayState(job, "jobstate"); 856 867 857 868 MythUIButtonListItem *sel_item = item->parent()->GetItemCurrent(); 858 if ((item != sel_item) && pginfo && item->GetImage("preview").isEmpty() && 859 (asAvailable == pginfo->GetAvailableStatus())) 869 if (item == sel_item) 870 return; 871 872 if ((asAvailable == pginfo->GetAvailableStatus()) && 873 GetLoadedPreview(*pginfo).isEmpty()) 860 874 { 861 875 QString token = m_helper.GetPreviewImage(*pginfo, true); 862 if (token.isEmpty()) 863 return; 864 865 m_preview_tokens.insert(token); 866 // now make sure selected item is still at the top of the queue 867 ProgramInfo *sel_pginfo = 868 qVariantValue<ProgramInfo*>(sel_item->GetData()); 869 if (sel_pginfo && sel_item->GetImage("preview").isEmpty() && 870 (asAvailable == sel_pginfo->GetAvailableStatus())) 876 if (!token.isEmpty()) 871 877 { 872 m_preview_tokens.insert( 873 m_helper.GetPreviewImage(*sel_pginfo, false)); 878 m_preview_tokens.insert(token); 879 // now make sure selected item is still at the top of the queue 880 ProgramInfo *sel_pginfo = 881 qVariantValue<ProgramInfo*>(sel_item->GetData()); 882 if (sel_pginfo && GetLoadedPreview(*sel_pginfo).isEmpty() && 883 (asAvailable == sel_pginfo->GetAvailableStatus())) 884 { 885 m_preview_tokens.insert( 886 m_helper.GetPreviewImage(*sel_pginfo, false)); 887 } 874 888 } 875 889 } 890 891 if (item->GetImage("preview").isEmpty()) 892 { 893 QString cachedPreview = GetStalePreview(*pginfo); 894 if (!cachedPreview.isEmpty()) 895 item->SetImage(cachedPreview, "preview", true); 896 } 876 897 } 877 898 899 /** \brief Returns a relatively up to date preview file name if available. 900 * This will only be returned after the preview generator hands us this 901 * preview file as an up to date preview file. This returns an empty string 902 * when not available. 903 * \sa GetStalePreview() 904 */ 905 QString PlaybackBox::GetLoadedPreview(const ProgramInfo &pginfo) const 906 { 907 PreviewCache::const_iterator it = 908 m_previewCache.find(pginfo.MakeUniqueKey()); 909 return (it == m_previewCache.end()) ? QString() : 910 ((*it).left(6) == "cache:") ? QString() : *it; 911 } 878 912 913 /** \brief Returns the most up to date preview we have in local storage. 914 * This image may be quite stale, as another frontent may have changed 915 * the file or the bookmarks since the last time it was shown on screen 916 * on this frontend. This is meant as a temporary placeholder image. 917 * \sa GetLoadedPreview() 918 */ 919 QString PlaybackBox::GetStalePreview(const ProgramInfo &pginfo) const 920 { 921 QString key = pginfo.MakeUniqueKey(); 922 PreviewCache::const_iterator it = m_previewCache.find(key); 923 QString ret; 924 if (it != m_previewCache.end()) 925 ret = ((*it).left(6) == "cache:") ? (*it).mid(6) : *it; 926 if (ret.left(12) == "<NOT_CACHED>") 927 return QString(); 928 else if (ret.length()) 929 return ret; 930 931 QString preview; 932 QString remotecachedirname = QString("%1/remotecache").arg(GetConfDir()); 933 QDir remotecachedir(remotecachedirname); 934 if (remotecachedir.exists()) 935 { 936 QString filename = QString("%1/%2") 937 .arg(remotecachedirname) 938 .arg(pginfo.GetBasename() + ".png"); 939 if (QFileInfo(filename).isReadable()) 940 preview = filename; 941 } 942 943 ret = m_previewCache[key] = QString("cache:") + 944 ((preview.isEmpty()) ? QString("<NOT_CACHED>") : preview); 945 ret = (ret.left(6) == "cache:") ? (ret).mid(6) : ret; 946 return (ret.left(12) == "<NOT_CACHED>") ? QString() : ret; 947 } 948 879 949 /** \brief Updates the UI properties for a new preview file. 880 950 * This first update the image property of the MythUIButtonListItem 881 951 * with the new preview file, then if it is selected and there is … … 946 1016 QString("Loading preview %1,\n\t\t\tmsg %2") 947 1017 .arg(previewFile).arg(message)); 948 1018 1019 m_previewCache[info->MakeUniqueKey()] = previewFile; 1020 949 1021 item->SetImage(previewFile, "preview", true); 950 1022 951 1023 if ((GetFocusWidget() == m_recordingList) && -
programs/mythfrontend/playbackbox.h
45 45 class MythDialogBox; 46 46 47 47 typedef QMap<QString,ProgramList> ProgramMap; 48 typedef QMap<QString,QString> PreviewCache; 48 49 typedef QMap<QString,QString> Str2StrMap; 49 50 50 51 enum { … … 327 328 328 329 QString CreateProgramInfoString(const ProgramInfo &program) const; 329 330 331 QString GetLoadedPreview(const ProgramInfo &pginfo) const; 332 QString GetStalePreview(const ProgramInfo &pginfo) const; 333 330 334 private: 331 335 QRegExp m_prefixes; ///< prefixes to be ignored when sorting 332 336 QRegExp m_titleChaff; ///< stuff to remove for search rules … … 398 402 // Main Recording List support 399 403 QStringList m_titleList; ///< list of pages 400 404 ProgramMap m_progLists; ///< lists of programs by page 405 mutable PreviewCache m_previewCache; 401 406 int m_progsInDB; ///< total number of recordings in DB 402 407 bool m_isFilling; 403 408
