Ticket #3938: mythweather.patch

File mythweather.patch, 4.0 KB (added by Joe Ripley <vitaminjoe@…>, 17 years ago)

Add ability to organize grabber scripts and related files into subdirectories of MythWeather? /usr/{local/}share/scripts directory

  • mythplugins/mythweather/mythweather/sourceManager.h

     
    4040    QPtrList<WeatherSource> m_sources; //in-use scripts
    4141    QIntDict<WeatherSource> m_sourcemap;
    4242    units_t m_units;
     43    void recurseDirs(QDir dir);
    4344};
    4445
    4546#endif
  • mythplugins/mythweather/mythweather/weatherSource.cpp

     
    386386    QStringList locs;
    387387
    388388    m_proc->clearArguments();
     389    m_proc->setWorkingDirectory(m_info->file->dir(true));
    389390    m_proc->addArgument(m_info->file->absFilePath());
    390391    m_proc->addArgument("-l");
    391392    m_proc->addArgument(str);
     
    421422    VERBOSE(VB_GENERAL, "Starting update of " + m_info->name);
    422423    m_data.clear();
    423424    m_proc->clearArguments();
     425    m_proc->setWorkingDirectory(m_info->file->dir(true));
    424426    m_proc->addArgument("nice");
    425427    m_proc->addArgument(m_info->file->absFilePath());
    426428    m_proc->addArgument("-u");
  • mythplugins/mythweather/mythweather/sourceManager.cpp

     
    7171{
    7272    QString path =  gContext->GetShareDir() + "mythweather/scripts/";
    7373    QDir dir(path);
    74     dir.setFilter(QDir::Executable | QDir::Files);
     74    dir.setFilter(QDir::Executable | QDir::Files | QDir::Dirs);
    7575    // this kinda goes against idea of keeping ui separate, but oh well
    76     MythProgressDialog bsydlg(tr("Searching for scripts"), dir.count());
    77     int progress = 0;
     76    MythProgressDialog bsydlg(tr("Searching for scripts"), 1);
    7877
    7978    if (!dir.exists())
    8079    {
     
    8281        return false;
    8382    }
    8483
    85     const QFileInfoList *files = dir.entryInfoList();
    86     if (!files)
    87         return false;
     84    bsydlg.setProgress(0);
     85    recurseDirs(dir);
     86    bsydlg.setProgress(1);
    8887
    89     QFileInfoListIterator itr(*files);
    90     QFileInfo *file;
    91     while ((file = itr.current()))
    92     {
    93         ++itr;
    94         if (file->isExecutable())
    95         {
    96             ScriptInfo *info = WeatherSource::probeScript(*file);
    97             if (info)
    98             {
    99                 m_scripts.append(info);
    100                 VERBOSE(VB_GENERAL, "found script " + file->absFilePath());
    101             }
    102         }
    103         bsydlg.setProgress(++progress);
    104     }
    10588    // run through and see if any scripts have been deleted
    10689    MSqlQuery db(MSqlQuery::InitCon());
    10790    QString query = "SELECT sourceid, path FROM weathersourcesettings "
     
    307290    WeatherSource *ws = m_sourcemap[screen->getId()];
    308291    ws->disconnectScreen(screen);
    309292}
     293
     294// Recurses dir for script files
     295void SourceManager::recurseDirs( QDir dir )
     296{
     297    if (!dir.exists())
     298        return;
     299
     300    dir.setFilter(QDir::Executable | QDir::Files | QDir::Dirs);
     301    const QFileInfoList *files = dir.entryInfoList();
     302    if (!files)
     303        return;
     304
     305    QFileInfoListIterator itr(*files);
     306    QFileInfo *file;
     307
     308    while ((file = itr.current()))
     309    {
     310        ++itr;
     311        if (file->isDir())
     312        {
     313            if (file->fileName() == QString("..")) continue;
     314            if (file->fileName() == QString("."))  continue;
     315            QDir recurseTo(file->filePath());
     316            recurseDirs(recurseTo);
     317        }
     318
     319        if (file->isExecutable() && !(file->isDir()))
     320        {
     321            ScriptInfo *info = WeatherSource::probeScript(*file);
     322            if (info)
     323            {
     324                m_scripts.append(info);
     325                VERBOSE(VB_GENERAL, "found script " + file->absFilePath());
     326            }
     327        }
     328    }
     329
     330    return;   
     331}