Ticket #303: extensions-mythtv.diff
File extensions-mythtv.diff, 9.8 KB (added by , 19 years ago) |
---|
-
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" … … 38 39 "MEDIATYPE_MIXED", 39 40 "MEDIATYPE_AUDIO", 40 41 "MEDIATYPE_DVD", 41 "MEDIATYPE_VCD" 42 "MEDIATYPE_VCD", 43 "MEDIATYPE_MMUSIC", 44 "MEDIATYPE_MVIDEO", 45 "MEDIATYPE_MGALLERY" 42 46 }; 43 47 44 48 const char* MythMediaDevice::MediaErrorStrings[] = … … 109 113 { 110 114 m_Status = MEDIASTAT_MOUNTED; 111 115 onDeviceMounted(); 116 DetectMediaType(); 112 117 } 113 118 else 114 119 onDeviceUnmounted(); … … 122 127 } 123 128 else 124 129 { 125 VERBOSE( VB_ALL, "Disk i serted on a supermount device" );130 VERBOSE( VB_ALL, "Disk inserted on a supermount device" ); 126 131 // If it's a super mount then the OS will handle mounting / unmounting. 127 132 // We just need to give derived classes a chance to perform their 128 133 // mount / unmount logic. 129 134 if (DoMount) 135 { 130 136 onDeviceMounted(); 137 DetectMediaType(); 138 } 131 139 else 132 140 onDeviceUnmounted(); 133 141 return true; … … 243 251 return m_Status; 244 252 } 245 253 254 255 // 256 // Try to make an educated guess about the type of data present on the Media. 257 // This fuction changes m_MediaType accordingly. 258 // 259 void MythMediaDevice::DetectMediaType(void) 260 { 261 262 ScanMediaType(m_MountPath); 263 if (ExtensionArray.isEmpty ()) 264 { 265 VERBOSE(VB_GENERAL, 266 QString("No files with extension found in '%1'").arg (m_MountPath)); 267 } else { 268 int score = 0, highscore = 0, type = 0; 269 270 ExtensionMap *em; 271 for (em = ExtensionMapList.first(); em; em = ExtensionMapList.next()) 272 { 273 QStringList::Iterator it; 274 for (it = em->Extensions.begin(); it != em->Extensions.end(); ++it) 275 { 276 if (ExtensionArray.contains(*it)) 277 score += ExtensionArray[*it]; 278 } 279 VERBOSE(VB_ALL, QString("Looking for: '%1', Score: %2") 280 .arg(MediaTypeStrings[ffs(em->Mediatype)]) 281 .arg(score)); 282 if (score > highscore) 283 type = em->Mediatype; highscore = score; 284 } 285 if (type != 0) 286 m_MediaType = (MediaType)type; 287 } 288 ExtensionArray.clear(); 289 } 290 291 // 292 // Recursively scan directories and create an associative array with 293 // key: 'tolower(extension)' and value the number of times we've 294 // seen it. 295 // 296 void MythMediaDevice::ScanMediaType(const QString& directory) 297 { 298 QDir d(directory); 299 300 d.setSorting(QDir::DirsFirst | QDir::Name | QDir::IgnoreCase); 301 if (!d.exists()) 302 return; 303 304 const QFileInfoList *list = d.entryInfoList(); 305 if (!list) 306 return; 307 308 QFileInfoListIterator it(*list); 309 QFileInfo *fi; 310 311 while ((fi = it.current()) != 0) 312 { 313 ++it; 314 if (fi->fileName() == "." || fi->fileName() == ".." ) 315 continue; 316 if (!fi->isDir()) 317 { 318 QString extension = fi->extension(false); 319 if (!extension.isEmpty()) 320 { 321 extension = extension.lower(); 322 if (ExtensionArray.contains(extension)) 323 ExtensionArray[extension]++; 324 else 325 ExtensionArray[extension] = 1; 326 } 327 } 328 else ScanMediaType(fi->absFilePath()); 329 } 330 } 331 332 // 333 // Allow Plugin's to register their supported MediaType and the file 334 // extensions that map to it. 335 // The extensions argument is a comma separated list of extensions like: 336 // 'mp3,ogg,flac'. 337 // 338 void MythMediaDevice::MediaRegisterExtensions(const int mediatype, const QString& extensions) 339 { 340 ExtensionMap *eMap = new ExtensionMap; 341 eMap->Mediatype = mediatype; 342 eMap->Extensions = QStringList::split(",", extensions, ""); 343 344 if (eMap->Extensions.count() == 0) 345 { 346 cerr << "Empty setting for entry: " << mediatype << endl; 347 delete eMap; 348 return; 349 } 350 ExtensionMapList.append(eMap); 351 } -
libs/libmyth/mythmediamonitor.h
57 57 void checkDevices(void); 58 58 void startMonitoring(void); 59 59 void stopMonitoring(void); 60 void MonitorRegisterExtensions(int mediaType, const QString &extensions); 60 61 QValueList <MythMediaDevice*> getMedias(MediaType mediatype); 61 62 62 63 static MediaMonitor* getMediaMonitor(); -
libs/libmyth/mythdialogs.cpp
660 660 const QString &description, 661 661 const QString &key, 662 662 void (*callback)(MythMediaDevice*mediadevice), 663 int mediaType) 663 int mediaType, 664 const QString &extensions) 664 665 { 665 666 (void)key; 666 667 … … 672 673 .arg(destination)); 673 674 674 675 d->mediaHandlerMap[destination] = mhd; 676 if (extensions != NULL) 677 { 678 MediaMonitor *mon = MediaMonitor::getMediaMonitor(); 679 if (mon == NULL) 680 { 681 cerr << "MythMainWindow::RegisterMediaHandler: " << 682 "Cannot get to MediaMonitor" << endl; 683 } else { 684 mon->MonitorRegisterExtensions(mediaType, extensions); 685 } 686 } 675 687 } 676 688 else 677 689 { -
libs/libmyth/mythmediamonitor.cpp
306 306 m_Thread.wait(); 307 307 } 308 308 309 // 310 // Register the extension list on all known devices 311 // 312 void MediaMonitor::MonitorRegisterExtensions(int mediaType, 313 const QString &extensions) 314 { 315 QValueList<MythMediaDevice*>::iterator itr = m_Devices.begin(); 316 MythMediaDevice* pDev; 317 while (itr != m_Devices.end()) 318 { 319 pDev = *itr; 320 if (pDev) 321 pDev->MediaRegisterExtensions(mediaType,extensions); 322 itr++; 323 } 324 325 } 326 // 309 327 // Ask for available media 310 328 QValueList <MythMediaDevice*> MediaMonitor::getMedias(MediaType mediatype) 311 329 { -
libs/libmyth/mythdialogs.h
60 60 61 61 #define REG_KEY(a, b, c, d) gContext->GetMainWindow()->RegisterKey(a, b, c, d) 62 62 #define REG_JUMP(a, b, c, d) gContext->GetMainWindow()->RegisterJump(a, b, c, d) 63 #define REG_MEDIA_HANDLER(a, b, c, d, e ) gContext->GetMainWindow()->RegisterMediaHandler(a, b, c, d, e)63 #define REG_MEDIA_HANDLER(a, b, c, d, e, f) gContext->GetMainWindow()->RegisterMediaHandler(a, b, c, d, e, f) 64 64 #define REG_MEDIAPLAYER(a,b,c) gContext->GetMainWindow()->RegisterMediaPlugin(a, b, c) 65 65 66 66 typedef int (*MediaPlayCallback)(const char*, const char*, const char*, const char*, int, const char*); … … 98 98 void RegisterMediaHandler(const QString &destination, 99 99 const QString &description, const QString &key, 100 100 void (*callback)(MythMediaDevice* mediadevice), 101 int mediaType); 101 int mediaType, 102 const QString &extensions); 102 103 103 104 void RegisterMediaPlugin(const QString &name, const QString &desc, 104 105 MediaPlayCallback fn); -
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, … … 19 20 MEDIATYPE_MIXED=4, 20 21 MEDIATYPE_AUDIO=8, 21 22 MEDIATYPE_DVD=16, 22 MEDIATYPE_VCD=32 23 MEDIATYPE_VCD=32, 24 MEDIATYPE_MMUSIC=64, 25 MEDIATYPE_MVIDEO=128, 26 MEDIATYPE_MGALLERY=256 23 27 } MediaType; 24 28 25 29 typedef enum { … … 73 77 bool mount() { return performMountCmd(true); } 74 78 bool unmount() { return performMountCmd(false); } 75 79 bool isMounted(bool bVerify = false); 80 81 void MediaRegisterExtensions(const int mediatype,const QString& extensions); 82 76 83 77 84 static const char* MediaStatusStrings[]; 78 85 static const char* MediaTypeStrings[]; … … 86 93 virtual void onDeviceMounted() {}; 87 94 virtual void onDeviceUnmounted() {}; 88 95 96 void DetectMediaType(void); 97 void ScanMediaType(const QString& directory); 89 98 MediaStatus setStatus(MediaStatus newStat, bool CloseIt=false); 90 99 91 100 QString m_MountPath; ///< The path to this media's mount point (i.e. /mnt/cdrom). Read only. … … 99 108 int m_DeviceHandle; ///< A file handle for opening and closing the device. 100 109 MediaType m_MediaType; ///< The type of media 101 110 bool m_SuperMount; ///< Is this a supermount device? 111 QMap<QString, int> ExtensionArray; ///< current tally of extensions on the disk 112 typedef struct { 113 int Mediatype; 114 QStringList Extensions; 115 } ExtensionMap; 116 QPtrList<ExtensionMap> ExtensionMapList; ///< Map extansions to a mediatype 117 102 118 }; 103 119 104 120 #endif