Ticket #303: 303.patch
File 303.patch, 11.8 KB (added by , 15 years ago) |
---|
-
mythplugins/mythdvd/mythdvd/main.cpp
273 273 void initKeys(void) 274 274 { 275 275 REG_JUMP("Play DVD", "Play a DVD", "", playDVD); 276 REG_MEDIA_HANDLER("MythDVD DVD Media Handler", "", "", handleDVDMedia, MEDIATYPE_DVD); 276 REG_MEDIA_HANDLER("MythDVD DVD Media Handler", "", "", 277 handleDVDMedia, MEDIATYPE_DVD, NULL); 278 277 279 REG_JUMP("Play VCD", "Play a VCD", "", playVCD); 278 REG_MEDIA_HANDLER("MythDVD VCD Media Handler", "", "", handleVCDMedia, MEDIATYPE_VCD); 280 REG_MEDIA_HANDLER("MythDVD VCD Media Handler", "", "", 281 handleVCDMedia, MEDIATYPE_VCD, NULL); 282 279 283 REG_JUMP("Rip DVD", "Import a DVD into your MythVideo database", "", 280 284 startDVDRipper); 281 285 } -
mythplugins/mythmusic/mythmusic/main.cpp
520 520 REG_KEY("Music", "INCSEARCHNEXT", "Incremental search find next match", "Ctrl+N"); 521 521 522 522 REG_MEDIA_HANDLER("MythMusic Media Handler", "", "", handleMedia, 523 MEDIATYPE_AUDIO | MEDIATYPE_MIXED );523 MEDIATYPE_AUDIO | MEDIATYPE_MIXED, NULL); 524 524 } 525 525 526 526 int mythplugin_init(const char *libversion) -
mythplugins/mythgallery/mythgallery/main.cpp
92 92 REG_KEY("Gallery", "DELETE", "Delete marked images or current image if none are marked", "D"); 93 93 REG_KEY("Gallery", "MARK", "Mark image", "T"); 94 94 95 REG_MEDIA_HANDLER("MythGallery Media Handler", "", "", handleMedia, MEDIATYPE_DATA | MEDIATYPE_MIXED); 95 REG_MEDIA_HANDLER("MythGallery Media Handler", "", "", handleMedia, 96 MEDIATYPE_DATA | MEDIATYPE_MIXED, NULL); 96 97 } 97 98 98 99 int mythplugin_init(const char *libversion) -
mythtv/libs/libmythui/mythmainwindow.cpp
908 908 const QString &description, 909 909 const QString &key, 910 910 void (*callback)(MythMediaDevice*mediadevice), 911 int mediaType) 911 int mediaType, 912 const QString &extensions) 912 913 { 913 914 (void)key; 914 915 … … 920 921 .arg(destination)); 921 922 922 923 d->mediaHandlerMap[destination] = mhd; 924 925 MediaMonitor *mon = NULL; 926 if (!extensions.isEmpty() && (mon = MediaMonitor::GetMediaMonitor())) 927 mon->MonitorRegisterExtensions(mediaType, extensions); 923 928 } 924 929 else 925 930 { -
mythtv/libs/libmythui/mythmainwindow.h
36 36 #define REG_KEY(a, b, c, d) GetMythMainWindow()->RegisterKey(a, b, c, d) 37 37 #define GET_KEY(a, b) GetMythMainWindow()->GetKey(a, b) 38 38 #define REG_JUMP(a, b, c, d) GetMythMainWindow()->RegisterJump(a, b, c, d) 39 #define REG_MEDIA_HANDLER(a, b, c, d, e ) GetMythMainWindow()->RegisterMediaHandler(a, b, c, d, e)39 #define REG_MEDIA_HANDLER(a, b, c, d, e, f) GetMythMainWindow()->RegisterMediaHandler(a, b, c, d, e, f) 40 40 #define REG_MEDIAPLAYER(a,b,c) GetMythMainWindow()->RegisterMediaPlugin(a, b, c) 41 41 42 42 typedef int (*MediaPlayCallback)(const char*, const char*, const char*, const char*, int, const char*); … … 70 70 void RegisterMediaHandler(const QString &destination, 71 71 const QString &description, const QString &key, 72 72 void (*callback)(MythMediaDevice* mediadevice), 73 int mediaType );73 int mediaType, const QString &extensions); 74 74 75 75 void RegisterMediaPlugin(const QString &name, const QString &desc, 76 76 MediaPlayCallback fn); -
mythtv/libs/libmyth/mythmedia.cpp
7 7 8 8 // Qt Headers 9 9 #include <qfile.h> 10 #include <qdir.h> 10 11 11 12 // MythTV headers 12 13 #include "mythmedia.h" … … 42 43 "MEDIATYPE_MIXED", 43 44 "MEDIATYPE_AUDIO", 44 45 "MEDIATYPE_DVD", 45 "MEDIATYPE_VCD" 46 "MEDIATYPE_VCD", 47 "MEDIATYPE_MMUSIC", 48 "MEDIATYPE_MVIDEO", 49 "MEDIATYPE_MGALLERY", 46 50 }; 47 51 48 52 const char* MythMediaDevice::MediaErrorStrings[] = … … 123 127 isMounted(true); 124 128 m_Status = MEDIASTAT_MOUNTED; 125 129 onDeviceMounted(); 130 DetectMediaType(); 126 131 } 127 132 else 128 133 onDeviceUnmounted(); … … 141 146 // We just need to give derived classes a chance to perform their 142 147 // mount / unmount logic. 143 148 if (DoMount) 149 { 144 150 onDeviceMounted(); 151 DetectMediaType(); 152 } 145 153 else 146 154 onDeviceUnmounted(); 147 155 return true; … … 149 157 return false; 150 158 } 151 159 160 // 161 // Try to make an educated guess about the type of data present on the Media. 162 // This fuction changes m_MediaType accordingly. 163 // 164 void MythMediaDevice::DetectMediaType(void) 165 { 166 ScanMediaType(m_MountPath); 167 168 if (ExtensionArray.isEmpty()) 169 { 170 VERBOSE(VB_GENERAL, QString("No files with extensions found in '%1'") 171 .arg(m_MountPath)); 172 return; 173 } 174 175 int score = 0, highscore = 0, type = 0; 176 177 const ExtensionMap *em; 178 for (em = ExtensionMapList.first(); em; em = ExtensionMapList.next()) 179 { 180 QStringList::const_iterator it; 181 for (it = em->Extensions.begin(); it != em->Extensions.end(); ++it) 182 { 183 if (ExtensionArray.contains(*it)) 184 score += ExtensionArray[*it]; 185 } 186 187 VERBOSE(VB_ALL, QString("Looking for: '%1', Score: %2") 188 .arg(MediaTypeStrings[ffs(em->Mediatype)]) 189 .arg(score)); 190 191 if (score > highscore) 192 type = em->Mediatype; 193 194 highscore = max(score, highscore); 195 196 score = 0; 197 } 198 199 if (type != 0) 200 m_MediaType = (MediaType)type; 201 202 ExtensionArray.clear(); 203 } 204 205 // 206 // Recursively scan directories and create an associative array with 207 // key: 'tolower(extension)' and value the number of times we've 208 // seen it. 209 // 210 void MythMediaDevice::ScanMediaType(const QString& directory) 211 { 212 QDir d(directory); 213 214 d.setSorting(QDir::DirsFirst | QDir::Name | QDir::IgnoreCase); 215 if (!d.exists()) 216 return; 217 218 const QFileInfoList *list = d.entryInfoList(); 219 if (!list) 220 return; 221 222 QFileInfoListIterator it(*list); 223 QFileInfo *fi; 224 225 while ((fi = it.current()) != 0) 226 { 227 ++it; 228 if (fi->fileName() == "." || fi->fileName() == ".." ) 229 continue; 230 if (!fi->isDir()) 231 { 232 QString extension = fi->extension(false); 233 if (!extension.isEmpty()) 234 { 235 extension = extension.lower(); 236 if (ExtensionArray.contains(extension)) 237 ExtensionArray[extension]++; 238 else 239 ExtensionArray[extension] = 1; 240 } 241 } 242 else ScanMediaType(fi->absFilePath()); 243 } 244 } 245 246 // 247 // Allow Plugin's to register their supported MediaType and the file 248 // extensions that map to it. 249 // The extensions argument is a comma separated list of extensions like: 250 // 'mp3,ogg,flac'. 251 // 252 void MythMediaDevice::MediaRegisterExtensions(const int mediatype, const QString& extensions) 253 { 254 ExtensionMap *eMap = new ExtensionMap; 255 eMap->Mediatype = mediatype; 256 eMap->Extensions = QStringList::split(",", extensions, ""); 257 258 if (eMap->Extensions.count() == 0) 259 { 260 VERBOSE(VB_IMPORTANT, QString("Empty setting for entry: '%1'") 261 .arg(mediatype)); 262 263 delete eMap; 264 return; 265 } 266 ExtensionMapList.append(eMap); 267 } 268 152 269 MediaError MythMediaDevice::eject(bool open_close) 153 270 { 154 271 (void) open_close; -
mythtv/libs/libmyth/mythmediamonitor.h
70 70 // it is safe to dereference the pointer. When finished call Unlock() 71 71 QValueList<MythMediaDevice*> GetMedias(MediaType mediatype); 72 72 73 void MonitorRegisterExtensions(int mediaType, const QString &extensions); 74 73 75 public slots: 74 76 void mediaStatusChanged(MediaStatus oldStatus, MythMediaDevice* pMedia); 75 77 -
mythtv/libs/libmyth/mythmediamonitor.cpp
842 842 return medias; 843 843 } 844 844 845 // 846 // Register the extension list on all known devices 847 // 848 void MediaMonitor::MonitorRegisterExtensions(int mediaType, 849 const QString &extensions) 850 { 851 QValueList<MythMediaDevice*>::iterator itr = m_Devices.begin(); 852 for (; itr != m_Devices.end(); ++itr) 853 { 854 if (*itr) 855 (*itr)->MediaRegisterExtensions(mediaType, extensions); 856 } 857 } 858 845 859 // Signal handler. 846 860 void MediaMonitor::mediaStatusChanged(MediaStatus oldStatus, 847 861 MythMediaDevice* pMedia) -
mythtv/libs/libmyth/mythmedia.h
3 3 4 4 #include <qobject.h> 5 5 #include <qstring.h> 6 #include <qstringlist.h> 6 7 7 8 typedef enum { 8 9 MEDIASTAT_ERROR, … … 20 21 MEDIATYPE_MIXED=4, 21 22 MEDIATYPE_AUDIO=8, 22 23 MEDIATYPE_DVD=16, 23 MEDIATYPE_VCD=32 24 MEDIATYPE_VCD=32, 25 MEDIATYPE_MMUSIC=64, 26 MEDIATYPE_MVIDEO=128, 27 MEDIATYPE_MGALLERY=256 24 28 } MediaType; 25 29 26 30 typedef enum { … … 76 80 bool mount() { return performMountCmd(true); } 77 81 bool unmount() { return performMountCmd(false); } 78 82 bool isMounted(bool bVerify = false); 83 84 void MediaRegisterExtensions(const int mediatype,const QString& extensions); 85 79 86 80 87 static const char* MediaStatusStrings[]; 81 88 static const char* MediaTypeStrings[]; … … 91 98 virtual void onDeviceMounted() {}; 92 99 virtual void onDeviceUnmounted() {}; 93 100 101 void DetectMediaType(void); 102 void ScanMediaType(const QString& directory); 94 103 MediaStatus setStatus(MediaStatus newStat, bool CloseIt=false); 95 104 96 105 QString m_MountPath; ///< The path to this media's mount point (i.e. /mnt/cdrom). Read only. … … 104 113 int m_DeviceHandle; ///< A file handle for opening and closing the device. 105 114 MediaType m_MediaType; ///< The type of media 106 115 bool m_SuperMount; ///< Is this a supermount device? 116 QMap<QString, int> ExtensionArray; ///< current tally of extensions on the disk 117 typedef struct { 118 int Mediatype; 119 QStringList Extensions; 120 } ExtensionMap; 121 QPtrList<ExtensionMap> ExtensionMapList; ///< Map extansions to a mediatype 122 107 123 }; 108 124 109 125 #endif