[mythtv] [PATCH] MythVideo & Mediamonitoring (suite)

Xavier Hervy maxpower44 at tiscali.fr
Wed Jun 16 17:46:18 EDT 2004


Leo Weppelman wrote:

> It looks like the culprit is O_EXCL. If I drop O_EXCL from the
> open() call. All seems to be well.
> 
> Unfortunately something is very wrong with mythvideo at the moment, lots of
>   'videotree.o: Uh Oh. Reference larger than count of browser_mode_files'
> 
> I'll re-get it and install your patch again. But this hampers the
> mediachange test a bit....
> 
> Leo.

You're right it's only O_EXCL that cause issue.

I try on 2.6.3 without supermount and 2.4.20 and know we can open device 
already mount or mount device already open.
Thx for your help.
then all 'close device' removed could be stay in source code.
But why close a device if we can keep it open ?

I will try again, and i don't have the 'videotree.o : Uh Oh ...' 
probably you should use a clean cvs version.

I have a warning when i compile videotree and i don't know how to remove 
it then if you know ....
I have also remove some old code i have put in comentary.

I have remove the /video_ts lower test because Donovan is probably right 
about udf filesystem.

And don't forget you should install the both patch (mythtv.diff and 
mythvideo.diff). and the others plugins shouldn't work with my patch 
know ...

Xavier
-------------- next part --------------
? mythtv/log
Index: mythtv/libs/libmyth/mythcdrom-linux.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcdrom-linux.cpp,v
retrieving revision 1.2
diff -u -r1.2 mythcdrom-linux.cpp
--- mythtv/libs/libmyth/mythcdrom-linux.cpp	12 Jun 2004 21:02:17 -0000	1.2
+++ mythtv/libs/libmyth/mythcdrom-linux.cpp	16 Jun 2004 21:27:55 -0000
@@ -3,7 +3,8 @@
 #include <linux/cdrom.h>        // old ioctls for cdrom
 #include <errno.h>
 #include "mythcontext.h"
-
+#include <linux/iso_fs.h>
+#include <unistd.h>
 #define ASSUME_WANT_AUDIO 1
 
 MediaError MythCDROMLinux::eject() 
@@ -67,7 +68,7 @@
         //cout << "MythCDROMLinux::checkMedia - ";
         //cout << "Test Media result != MEDIAERR_OK" << endl;
         m_MediaType = MEDIATYPE_UNKNOWN;
-        return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+        return setStatus(MEDIASTAT_UNKNOWN);
     }
 
     //cout << "MythCDROMLinux::checkMedia - ";
@@ -85,31 +86,31 @@
                 //cout << "disk ok - ";
                 if (isMounted(true))
                     //cout << "it's mounted" << endl;
-                    return setStatus(MEDIASTAT_MOUNTED, OpenedHere);
+                    return setStatus(MEDIASTAT_MOUNTED);
                 // If the disk is ok but not yet mounted we'll test it further down after this switch exits.
                 break;
             case CDS_TRAY_OPEN:
             case CDS_NO_DISC:
                 //cout << "Tray open or no disc" << endl;
                 m_MediaType = MEDIATYPE_UNKNOWN;
-                return setStatus(MEDIASTAT_OPEN, OpenedHere);
+                return setStatus(MEDIASTAT_OPEN);
                 break;
             case CDS_NO_INFO:
             case CDS_DRIVE_NOT_READY:
                 //cout << "No info or drive not ready" << endl;
                 m_MediaType = MEDIATYPE_UNKNOWN;
-                return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+                return setStatus(MEDIASTAT_UNKNOWN);
             default:
                 //cout << "unknown result from ioctl (" << ret << ")" << endl;
                 m_MediaType = MEDIATYPE_UNKNOWN;
-                return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+                return setStatus(MEDIASTAT_UNKNOWN);
         }
 
         if (mediaChanged()) 
         {
             //cout << "media changed - ";
             // Regardless of the actual status lie here and say it's open for now, so we can over the case of a missed open.
-            return setStatus(MEDIASTAT_OPEN, OpenedHere);
+            return setStatus(MEDIASTAT_OPEN);
         } 
         else 
         {
@@ -127,12 +128,23 @@
                         //cout << "found a data disk" << endl;
                         // We'll return NOTMOUNTED  here because we're switching media.
                         // The base class will try to mount the deivce causing the next pass to pick up the MOUNTED status.
-                        return setStatus(MEDIASTAT_NOTMOUNTED, OpenedHere);
+                        //grab volumeinfo from iso9660
+                        struct iso_primary_descriptor buf;
+                        lseek(this->m_DeviceHandle,(off_t) 2048*16,SEEK_SET);
+                        read(this->m_DeviceHandle,&buf,2048);
+                        this->m_VolumeID = QString(buf.volume_id).stripWhiteSpace();
+                        this->m_KeyID = QString("%1%2")
+                                        .arg(this->m_VolumeID)
+                                        .arg(QString(buf.creation_date).left(16));
+                      // QString date_creation = QString(buf.creation_date).left(16);
+                        cout << "VolumeID " << this->m_VolumeID << endl;
+                       cout << "KeyID "<<this->m_KeyID << endl; 
+                        return setStatus(MEDIASTAT_NOTMOUNTED);
                         break;
                     case CDS_AUDIO:
                         //cout << "found an audio disk" << endl;
                         m_MediaType = MEDIATYPE_AUDIO;
-                        return setStatus(MEDIASTAT_USEABLE, OpenedHere);
+                        return setStatus(MEDIASTAT_USEABLE);
                         break;
                     case CDS_MIXED:
                         m_MediaType = MEDIATYPE_MIXED;
@@ -140,30 +152,30 @@
                         // Note: Mixed mode CDs require an explixit mount call since we'll usually want the audio portion.
                         //         undefine ASSUME_WANT_AUDIO to change this behavior.
                         #ifdef ASSUME_WANT_AUDIO
-                            return setStatus(MEDIASTAT_USEABLE, OpenedHere);
+                            return setStatus(MEDIASTAT_USEABLE);
                         #else
                             mount();
-                            return setStatus(MEDIASTAT_NOTMOUNTED, OpenedHere);
+                            return setStatus(MEDIASTAT_NOTMOUNTED);
                         #endif
                         break;
                     case CDS_NO_INFO:
                     case CDS_NO_DISC:
                         //cout << "found no disk" << endl;
                         m_MediaType = MEDIATYPE_UNKNOWN;
-                        return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+                        return setStatus(MEDIASTAT_UNKNOWN);
                         break;
                     default:
                         //cout << "found unknown disk type" << endl;
                         fprintf(stderr, "Unknown data type: %d\n", type);
                         m_MediaType = MEDIATYPE_UNKNOWN;
-                        return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+                        return setStatus(MEDIASTAT_UNKNOWN);
                 }            
             }
             else if (m_Status == MEDIASTAT_MOUNTED || 
                      m_Status == MEDIASTAT_NOTMOUNTED) 
             {
                 //cout << "current status == " << MythMediaDevice::MediaStatusStrings[m_Status] << " setting status to not mounted - ";
-                setStatus(MEDIASTAT_NOTMOUNTED, OpenedHere);
+                setStatus(MEDIASTAT_NOTMOUNTED);
             }
 
             if (m_AllowEject)
@@ -174,12 +186,9 @@
     {
         //cout << "device not open returning unknown" << endl;
         m_MediaType = MEDIATYPE_UNKNOWN;
-        return setStatus(MEDIASTAT_UNKNOWN, OpenedHere);
+        return setStatus(MEDIASTAT_UNKNOWN);
     }
 
-    if (OpenedHere)
-        closeDevice();
-
     //cout << "returning " << MythMediaDevice::MediaStatusStrings[m_Status] << endl;
     return m_Status;
 }
Index: mythtv/libs/libmyth/mythcdrom.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcdrom.cpp,v
retrieving revision 1.7
diff -u -r1.7 mythcdrom.cpp
--- mythtv/libs/libmyth/mythcdrom.cpp	4 Jun 2004 02:31:22 -0000	1.7
+++ mythtv/libs/libmyth/mythcdrom.cpp	16 Jun 2004 21:27:55 -0000
@@ -55,17 +55,17 @@
 void MythCDROM::onDeviceMounted()
 {
     QString DetectPath;
-    DetectPath.sprintf("%s%s", (const char*)m_MountPath, PATHTO_DVD_DETECT);
-    VERBOSE(VB_ALL, QString("Looking for: '%1'").arg(DetectPath));
 
     struct stat sbuf;
+    DetectPath.sprintf("%s%s", (const char*)m_MountPath,PATHTO_DVD_DETECT);
+    VERBOSE(VB_ALL, QString("Looking for: '%1'").arg(DetectPath));
     if (stat(DetectPath, &sbuf) == 0)
-    {
-        VERBOSE(VB_GENERAL, "Probable DVD detected.");
-        m_MediaType = MEDIATYPE_DVD;
-        // HACK make it possible to eject a DVD by unmounting it
-        performMountCmd(false);
-        m_Status = MEDIASTAT_USEABLE; 
+    { 
+            VERBOSE(VB_GENERAL, "Probable DVD detected.");
+            m_MediaType = MEDIATYPE_DVD;
+            // HACK make it possible to eject a DVD by unmounting it
+            performMountCmd(false);
+            m_Status = MEDIASTAT_USEABLE; 
     }
     
     DetectPath.sprintf("%s%s", (const char*)m_MountPath, PATHTO_VCD_DETECT);
Index: mythtv/libs/libmyth/mythcontext.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.cpp,v
retrieving revision 1.121
diff -u -r1.121 mythcontext.cpp
--- mythtv/libs/libmyth/mythcontext.cpp	25 Apr 2004 14:59:40 -0000	1.121
+++ mythtv/libs/libmyth/mythcontext.cpp	16 Jun 2004 21:27:56 -0000
@@ -91,6 +91,8 @@
     int m_logenable, m_logmaxcount, m_logprintlevel;
     QMap<QString,int> lastLogCounts;
     QMap<QString,QString> lastLogStrings;
+
+    MediaMonitor * media_monitor;
 };
 
 MythContextPrivate::MythContextPrivate(MythContext *lparent)
@@ -114,6 +116,8 @@
 
     m_db = QSqlDatabase::addDatabase("QMYSQL3", "MythContext");
     screensaver = new ScreenSaverControl();
+
+    media_monitor = NULL;
 }
 
 void MythContextPrivate::Init(bool gui, bool lcd)
@@ -1226,6 +1230,19 @@
     d->m_settings->SetSetting(key, newValue);
 }
 
+void MythContext::SetMediaMonitor(MediaMonitor * lmediamonitor)
+{
+    d->media_monitor = lmediamonitor;
+}
+
+QValueList <MythMediaDevice*> MythContext::GetMedias(MediaType mediatype)
+{
+    QValueList <MythMediaDevice*> medias;
+    if (d->media_monitor != NULL)
+        medias = d->media_monitor->getMedias(mediatype);
+    return medias;
+}
+
 bool MythContext::SendReceiveStringList(QStringList &strlist, bool quickTimeout)
 {
     d->serverSockLock.lock();
Index: mythtv/libs/libmyth/mythcontext.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythcontext.h,v
retrieving revision 1.149
diff -u -r1.149 mythcontext.h
--- mythtv/libs/libmyth/mythcontext.h	4 Jun 2004 05:37:55 -0000	1.149
+++ mythtv/libs/libmyth/mythcontext.h	16 Jun 2004 21:27:56 -0000
@@ -15,6 +15,10 @@
 
 #include <iostream>
 #include <vector>
+
+#include <mythmediamonitor.h>
+#include <mythmedia.h>
+
 using namespace std;
 
 #if (QT_VERSION < 0x030100)
@@ -160,6 +164,9 @@
 
     void SetSetting(const QString &key, const QString &newValue);
 
+    void SetMediaMonitor(MediaMonitor * lmediamonitor);
+    QValueList <MythMediaDevice*> GetMedias(MediaType mediatype);
+
     QFont GetBigFont();
     QFont GetMediumFont();
     QFont GetSmallFont();
Index: mythtv/libs/libmyth/mythdialogs.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.cpp,v
retrieving revision 1.74
diff -u -r1.74 mythdialogs.cpp
--- mythtv/libs/libmyth/mythdialogs.cpp	5 Jun 2004 04:01:42 -0000	1.74
+++ mythtv/libs/libmyth/mythdialogs.cpp	16 Jun 2004 21:27:57 -0000
@@ -76,7 +76,7 @@
 
 struct MHData
 {
-    void (*callback)(void);
+    void (*callback)(MythMediaDevice * mediadevice);
     int MediaType;
     QString destination;
     QString description;
@@ -110,6 +110,10 @@
 
     void (*exitmenucallback)(void);
 
+    void (*exitmenumediadevicecallback)(MythMediaDevice *);
+    MythMediaDevice * mediadeviceforcallback;
+
+
     int escapekey;
 };
 
@@ -147,6 +151,8 @@
     d->ignore_lirc_keys = false;
     d->exitingtomain = false;
     d->exitmenucallback = false;
+    d->exitmenumediadevicecallback = false;
+    d->mediadeviceforcallback = NULL;
     d->escapekey = Key_Escape;
 
 #ifdef USE_LIRC
@@ -305,6 +311,14 @@
                 d->exitmenucallback = NULL;
 
                 callback();
+            }else if(d->exitmenumediadevicecallback && d->mediadeviceforcallback)
+            {
+                void (*callback)(MythMediaDevice *)= d->exitmenumediadevicecallback;
+                d->exitmenumediadevicecallback = NULL;
+                MythMediaDevice * mediadevice = d->mediadeviceforcallback;
+                d->mediadeviceforcallback = NULL;
+
+                callback(mediadevice);
             }
         }
     }
@@ -499,7 +513,7 @@
 void MythMainWindow::RegisterMediaHandler(const QString &destination,
                                           const QString &description,
                                           const QString &key, 
-                                          void (*callback)(void),
+                                          void (*callback)(MythMediaDevice * mediadevice),
                                           int mediaType)
 {
     (void)key;
@@ -597,7 +611,8 @@
                 {
                     cout << "Found a handler" << endl;
                     d->exitingtomain = true;
-                    d->exitmenucallback = itr.data().callback;
+                    d->exitmenumediadevicecallback = itr.data().callback;
+                    d->mediadeviceforcallback= pDev;
                     QApplication::postEvent(this, new ExitToMainMenuEvent());
                     break;
                 }
Index: mythtv/libs/libmyth/mythdialogs.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythdialogs.h,v
retrieving revision 1.37
diff -u -r1.37 mythdialogs.h
--- mythtv/libs/libmyth/mythdialogs.h	25 May 2004 05:08:53 -0000	1.37
+++ mythtv/libs/libmyth/mythdialogs.h	16 Jun 2004 21:27:57 -0000
@@ -91,7 +91,7 @@
                       const QString &key, void (*callback)(void));
     void RegisterMediaHandler(const QString &destination, 
                               const QString &description, const QString &key, 
-                              void (*callback)(void), int mediaType);
+                              void (*callback)(MythMediaDevice * mediadevice), int mediaType);
 
     void RegisterMediaPlugin(const QString &name, const QString &desc, 
                              MediaPlayCallback fn);
Index: mythtv/libs/libmyth/mythmedia.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmedia.cpp,v
retrieving revision 1.6
diff -u -r1.6 mythmedia.cpp
--- mythtv/libs/libmyth/mythmedia.cpp	12 Jun 2004 21:02:17 -0000	1.6
+++ mythtv/libs/libmyth/mythmedia.cpp	16 Jun 2004 21:27:57 -0000
@@ -43,8 +43,10 @@
     if (isDeviceOpen())
         return true;
  
-    m_DeviceHandle = open(m_DevicePath, O_RDONLY | O_NONBLOCK | O_EXCL);
-    
+//    m_DeviceHandle = open(m_DevicePath, O_RDONLY | O_NONBLOCK | O_EXCL);
+    // remove O_EXCL that prevent a mount drive to be open
+    m_DeviceHandle = open(m_DevicePath, O_RDONLY | O_NONBLOCK);
+  
     return isDeviceOpen();
 }
 
@@ -69,9 +71,6 @@
 {
     QString MountCommand;
     
-    if (isDeviceOpen())
-        closeDevice();
-
     if (!m_SuperMount) 
     {
         // Build a command line for mount/unmount and execute it...  Is there a better way to do this?
@@ -79,8 +78,11 @@
             MountCommand.sprintf("%s %s", PATHTO_MOUNT, 
                                  (const char*)m_DevicePath);
         else
+        {
             MountCommand.sprintf("%s %s", PATHTO_UNMOUNT, 
                                  (const char*)m_DevicePath);
+            closeDevice();
+        }
     
         VERBOSE(VB_ALL,  QString("Executing '%1'").arg(MountCommand));
         if (0 == system(MountCommand)) 
@@ -91,13 +93,16 @@
                 onDeviceMounted();
             }
             else
-                onDeviceUnmounted();
+            {
+               m_Status = MEDIASTAT_NOTMOUNTED;
+               onDeviceUnmounted();
+            }
             return true;
         }
         else
         {
-            VERBOSE(VB_GENERAL, QString("Failed to mount %1.")
-                                       .arg(m_DevicePath));
+            VERBOSE(VB_GENERAL, QString("Failed to %1.")
+                                       .arg(MountCommand));
         }
     } 
     else 
@@ -179,7 +184,7 @@
     return false;
 }
 
-MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus, bool CloseIt )
+MediaStatus MythMediaDevice::setStatus( MediaStatus NewStatus)
 {
     MediaStatus OldStatus = m_Status;
 
@@ -203,8 +208,11 @@
                 // as MEDIASTAT_OPEN, MEDISTAT_ERROR or MEDIASTAT_UNKNOWN.
                 mount();
                 break;
-            case MEDIASTAT_UNKNOWN:
+            case MEDIASTAT_UNKNOWN:break;
             case MEDIASTAT_OPEN:
+                if (MEDIASTAT_MOUNTED == OldStatus)
+                   unmount();
+                break;
             case MEDIASTAT_USEABLE:
             case MEDIASTAT_MOUNTED:
                 // get rid of the compiler warning...
@@ -217,9 +225,6 @@
     }
 
 
-    if (CloseIt)
-        closeDevice();
-
     return m_Status;
 }
 
Index: mythtv/libs/libmyth/mythmedia.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmedia.h,v
retrieving revision 1.3
diff -u -r1.3 mythmedia.h
--- mythtv/libs/libmyth/mythmedia.h	24 Feb 2004 07:31:08 -0000	1.3
+++ mythtv/libs/libmyth/mythmedia.h	16 Jun 2004 21:27:57 -0000
@@ -45,6 +45,7 @@
     MediaStatus getStatus() const { return m_Status; }
 
     const QString& getVolumeID() const { return m_VolumeID; }
+    const QString& getKeyID() const { return m_KeyID; }
 
     bool getAllowEject() const { return m_AllowEject; }
     void setAllowEject(bool allowEject) { m_AllowEject = allowEject; }
@@ -85,12 +86,14 @@
     virtual void onDeviceMounted() {};
     virtual void onDeviceUnmounted() {};
 
-    MediaStatus setStatus(MediaStatus newStat, bool CloseIt=false);
+    MediaStatus setStatus(MediaStatus newStat);
 
     QString m_MountPath;        ///< The path to this media's mount point (i.e. /mnt/cdrom). Read only.
     QString m_DevicePath;       ///< The path to this media's device (i.e. /dev/cdrom). Read/write.
     MediaStatus m_Status;       ///< The status of the media as of the last call to checkMedia. Read only.
     QString m_VolumeID;         ///< The volume ID of the media. Read Only.
+    QString m_KeyID;         ///< The Key ID of the media. Read Only.
+                             // For iso 9660 VolumeID + creation date
     bool m_Locked;              ///< Is this media locked? Read only.
     bool m_AllowEject;          ///< Allow the user to eject the media? Read/write.
     int m_DeviceHandle;         ///< A file handle for opening and closing the device.
Index: mythtv/libs/libmyth/mythmediamonitor.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmediamonitor.cpp,v
retrieving revision 1.7
diff -u -r1.7 mythmediamonitor.cpp
--- mythtv/libs/libmyth/mythmediamonitor.cpp	12 Jun 2004 21:02:17 -0000	1.7
+++ mythtv/libs/libmyth/mythmediamonitor.cpp	16 Jun 2004 21:27:58 -0000
@@ -286,6 +286,23 @@
     m_Thread.wait();
 }
 
+//Ask for available media
+QValueList <MythMediaDevice*> MediaMonitor::getMedias(MediaType mediatype)
+{
+    QValueList <MythMediaDevice*> medias;
+    QValueList <MythMediaDevice*>::Iterator itr = m_Devices.begin();
+    MythMediaDevice* pDev;
+    while (itr!=m_Devices.end())
+    {
+        pDev = *itr;
+        if ((pDev->getMediaType()==mediatype) &&
+            ((pDev->getStatus()==MEDIASTAT_USEABLE) ||
+            (pDev->getStatus()==MEDIASTAT_MOUNTED)))
+            medias.push_back(pDev);
+        itr++;
+    }
+    return medias;
+}
 // Signal handler.
 void MediaMonitor::mediaStatusChanged(MediaStatus oldStatus, 
                                       MythMediaDevice* pMedia)
Index: mythtv/libs/libmyth/mythmediamonitor.h
===================================================================
RCS file: /var/lib/mythcvs/mythtv/libs/libmyth/mythmediamonitor.h,v
retrieving revision 1.3
diff -u -r1.3 mythmediamonitor.h
--- mythtv/libs/libmyth/mythmediamonitor.h	12 Jun 2004 21:02:17 -0000	1.3
+++ mythtv/libs/libmyth/mythmediamonitor.h	16 Jun 2004 21:27:58 -0000
@@ -55,6 +55,7 @@
     void checkDevices(void);
     void startMonitoring(void);
     void stopMonitoring(void);
+    QValueList <MythMediaDevice*> getMedias(MediaType mediatype);
 
   public slots:
     void mediaStatusChanged( MediaStatus oldStatus, MythMediaDevice* pMedia);
Index: mythtv/programs/mythfrontend/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythtv/programs/mythfrontend/main.cpp,v
retrieving revision 1.145
diff -u -r1.145 main.cpp
--- mythtv/programs/mythfrontend/main.cpp	29 May 2004 18:30:46 -0000	1.145
+++ mythtv/programs/mythfrontend/main.cpp	16 Jun 2004 21:27:58 -0000
@@ -995,6 +995,7 @@
         mon->addFSTab();
         VERBOSE(VB_ALL, QString("Starting media monitor."));
         mon->startMonitoring();
+        gContext->SetMediaMonitor(mon);
     }
 #endif
 
-------------- next part --------------
Index: mythvideo/settings.pro
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/settings.pro,v
retrieving revision 1.6
diff -u -r1.6 settings.pro
--- mythvideo/settings.pro	4 Aug 2003 01:05:51 -0000	1.6
+++ mythvideo/settings.pro	16 Jun 2004 21:35:57 -0000
@@ -4,6 +4,7 @@
 PREFIX = /usr/local
 
 INCLUDEPATH += $${PREFIX}/include
+INCLUDEPATH += $${PREFIX}/include/mythtv
 INCLUDEPATH *= /usr/local/include
 
 DEFINES += _GNU_SOURCE
Index: mythvideo/mythvideo/main.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/main.cpp,v
retrieving revision 1.31
diff -u -r1.31 main.cpp
--- mythvideo/mythvideo/main.cpp	12 Jun 2004 17:35:12 -0000	1.31
+++ mythvideo/mythvideo/main.cpp	16 Jun 2004 21:35:59 -0000
@@ -29,6 +29,7 @@
 #include <mythtv/themedmenu.h>
 #include <mythtv/mythcontext.h>
 #include <mythtv/mythplugin.h>
+#include <mythtv/mythmedia.h>
 
 enum VideoFileLocation
 {
@@ -54,6 +55,10 @@
 void runVideoBrowser(void);
 void runVideoTree(void);
 void runVideoGallery(void);
+void runMediaHandle(MythMediaDevice * mediadevice)
+{
+     runVideoTree();
+}
 
 void setupKeys(void)
 {
@@ -74,7 +79,7 @@
     REG_KEY("Video","INCPARENT","Increase Parental Level","Right");
     REG_KEY("Video","DECPARENT","Decrease Parental Level","Left");
 
-
+    REG_MEDIA_HANDLER("Myth Video CD/DVD DATA Media handler","","",runMediaHandle,MEDIATYPE_DATA);
 }
 
 
Index: mythvideo/mythvideo/videotree.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videotree.cpp,v
retrieving revision 1.28
diff -u -r1.28 videotree.cpp
--- mythvideo/mythvideo/videotree.cpp	10 Apr 2004 18:52:28 -0000	1.28
+++ mythvideo/mythvideo/videotree.cpp	16 Jun 2004 21:36:01 -0000
@@ -12,6 +12,7 @@
 #include <mythtv/mythwidgets.h>
 #include <mythtv/uitypes.h>
 #include <mythtv/util.h>
+#include <mythtv/mythmedia.h>
 
 VideoTree::VideoTree(MythMainWindow *parent, QSqlDatabase *ldb,
                      QString window_name, QString theme_filename,
@@ -30,16 +31,23 @@
 
     wireUpTheme();
     video_tree_root = new GenericTree("video root", -2, false);
-    video_tree_data = video_tree_root->addNode("videos", -2, false);
+ //   video_tree_data = video_tree_root->addNode("videos", -2, false);
 
     buildVideoList();
+
+
     
     //  
     //  Tell the tree list to highlight the 
     //  first entry and then display it
     //
-    
-    video_tree_list->setCurrentNode(video_tree_data);
+    for (int i=0; i < video_tree_root->childCount();i++){
+	    video_tree_data = video_tree_root->getChildAt(i,0);
+	    if ((video_tree_data->childCount()>0) 
+		&& (video_tree_data->getChildAt(0,0)->getString() !=
+			tr("No files found"))) break;
+    }
+   video_tree_list->setCurrentNode(video_tree_data);
     if(video_tree_data->childCount() > 0)
     {
         video_tree_list->setCurrentNode(video_tree_data->getChildAt(0, 0));
@@ -254,6 +262,9 @@
     }
 }
 
+void VideoTree::GetMountPoints(){
+    
+}
 void VideoTree::buildVideoList()
 {
     if(file_browser)
@@ -262,21 +273,55 @@
         //  Fill metadata from directory structure
         //
         
-        buildFileList(gContext->GetSetting("VideoStartupDir"));
+        QStringList nodesname;
+        QStringList nodespath;
 
+        nodespath.append(gContext->GetSetting("VideoStartupDir"));
+        nodesname.append("videos");
+        QValueList<MythMediaDevice*> medias = gContext->GetMedias(MEDIATYPE_DATA);
+        QValueList<MythMediaDevice*>::Iterator itr = medias.begin();
+        MythMediaDevice * pDev;
+        while (itr != medias.end())
+        {
+           pDev = *itr;
+           if (pDev){
+                QString path = pDev->getMountPath();
+                QString name = path.right(path.length()-path.findRev("/")-1);
+		cout << "adding " << path << " as " << name << endl;
+                nodespath.append(path);
+                nodesname.append(name);
+          }
+           itr++;
+        }
+
+	for (uint j=0;j<nodesname.count();j++){
+		video_tree_data = video_tree_root->addNode(nodesname[j], -2, false);
+
+		//browser_mode_files.clear();
+
+        	buildFileList(nodespath[j]);
+	}
+	int mainnodeindex=0;
+	QString prefix = nodespath[mainnodeindex];
+        GenericTree *where_to_add = video_tree_root->getChildAt(mainnodeindex);
         for(uint i=0; i < browser_mode_files.count(); i++)
         {
             QString file_string = *(browser_mode_files.at(i));
-            QString prefix = gContext->GetSetting("VideoStartupDir");
-            if(prefix.length() < 1)
+
+            if (prefix.compare(file_string.left(prefix.length()))!=0){
+		mainnodeindex++;
+	    }
+	if (mainnodeindex < nodespath.count()){
+			prefix = nodespath[mainnodeindex];
+			where_to_add = video_tree_root->getChildAt(mainnodeindex	);
+	}
+    if(prefix.length() < 1)
             {
                 cerr << "videotree.o: Seems unlikely that this is going to work" << endl;
             }
             file_string.remove(0, prefix.length());
             QStringList list(QStringList::split("/", file_string));
 
-            GenericTree *where_to_add;
-            where_to_add = video_tree_data;
             int a_counter = 0;
             QStringList::Iterator an_it = list.begin();
             for( ; an_it != list.end(); ++an_it)
@@ -319,6 +364,8 @@
         //  widget that handles navigation
         //
 
+ 	video_tree_data = video_tree_root->addNode("videos", -2, false);
+
         QSqlQuery query("SELECT intid FROM videometadata ;", db);
         Metadata *myData;
     
Index: mythvideo/mythvideo/videotree.h
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videotree.h,v
retrieving revision 1.7
diff -u -r1.7 videotree.h
--- mythvideo/mythvideo/videotree.h	2 Sep 2003 20:09:53 -0000	1.7
+++ mythvideo/mythvideo/videotree.h	16 Jun 2004 21:36:01 -0000
@@ -25,6 +25,7 @@
               const char *name = 0);
    ~VideoTree();
 
+    void GetMountPoints();
     void buildVideoList();
     void buildFileList(QString directory);
     bool ignoreExtension(QString extension);


More information about the mythtv-dev mailing list