[mythtv] [patch] add mediamonitor to context and use in mythvideo

Leo Weppelman leo at wau.mis.ah.nl
Thu Aug 26 06:36:18 EDT 2004


On Thu, Aug 26, 2004 at 05:38:41AM -0400, J. Donavan Stanley wrote:
> Isaac,
> 
> Care to comment on the placement of the libmyth portion of this?  I know 
> you've had reservations in the past about things going into MythContext...

As Xavier just pointed out (thanks!) it also works without the context
portion. I just tested this and it works. A new patch is attached.

Leo.
-------------- next part --------------
Index: mythvideo/mythvideo/videotree.cpp
===================================================================
RCS file: /var/lib/mythcvs/mythvideo/mythvideo/videotree.cpp,v
retrieving revision 1.31
diff -u -r1.31 videotree.cpp
--- mythvideo/mythvideo/videotree.cpp	22 Aug 2004 18:16:32 -0000	1.31
+++ mythvideo/mythvideo/videotree.cpp	26 Aug 2004 10:27:27 -0000
@@ -12,6 +12,8 @@
 #include <mythtv/mythwidgets.h>
 #include <mythtv/uitypes.h>
 #include <mythtv/util.h>
+#include <mythtv/mythmedia.h>
+#include <mythtv/mythmediamonitor.h>
 
 #include "videofilter.h"
 const long WATCHED_WATERMARK = 10000; // Less than this and the chain of videos will 
@@ -39,7 +41,6 @@
 
     wireUpTheme();
     video_tree_root = new GenericTree("video root", -2, false);
-    video_tree_data = video_tree_root->addNode("videos", -2, false);
     
     currentVideoFilter = new VideoFilterSettings(db, true);
     
@@ -285,21 +286,74 @@
         //  Fill metadata from directory structure
         //
         
-        buildFileList(gContext->GetSetting("VideoStartupDir"));
+        QStringList nodesname;
+        QStringList nodespath;
+
+        nodespath.append(gContext->GetSetting("VideoStartupDir"));
+        nodesname.append("videos");
+
+
+        //
+        // See if there are removable media available, so we can add them
+        // to the tree.
+        //
+        MediaMonitor * mon = MediaMonitor::getMediaMonitor();
+        if (mon)
+        {
+            QValueList <MythMediaDevice*> medias =
+                                        mon->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);
+                    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);
+            buildFileList(nodespath[j]);
+        }
+
+        unsigned 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.compare(file_string.left(prefix.length())) != 0)
+            {
+                if (mainnodeindex++ < nodespath.count()) {
+                    prefix = nodespath[mainnodeindex];
+                }
+                else {
+                    cerr << "videotree.o: mainnodeindex out of bounds" << endl;
+                    break;
+                }
+            }
+            where_to_add = video_tree_root->getChildAt(mainnodeindex);
             if(prefix.length() < 1)
             {
-                cerr << "videotree.o: Seems unlikely that this is going to work" << endl;
+                cerr << "videotree.o: weird prefix.lenght" << endl;
+                break;
             }
+
             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)
@@ -308,7 +362,6 @@
                 {
                     QString title = (*an_it);
                     where_to_add->addNode(title.section(".",0,-2), i, true);
-                    
                 }
                 else
                 {


More information about the mythtv-dev mailing list