Skip to content

Commit

Permalink
Allow --jumppoint and --runplugin to print available destinations
Browse files Browse the repository at this point in the history
This adds methods to MythMainWindow and MythPluginManager to allow
enumeration of available jump points and plugins, and uses it to list
them when an invalid one is supplied on the command line. This causes a
ABI bump.

Also, this moves the code to load a specific plugin to just prior to
normal program init in the frontend, ensuring certain background tasks
get initialized.

Refs #10135
  • Loading branch information
wagnerrp committed Nov 16, 2011
1 parent c293896 commit ca52816
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 27 deletions.
15 changes: 12 additions & 3 deletions mythtv/libs/libmyth/mythplugin.cpp
Expand Up @@ -19,8 +19,8 @@

using namespace std;

MythPlugin::MythPlugin(const QString &libname)
: QLibrary(libname)
MythPlugin::MythPlugin(const QString &libname, const QString &plugname)
: QLibrary(libname), m_plugName(plugname)
{
enabled = true;
position = 0;
Expand Down Expand Up @@ -178,7 +178,7 @@ bool MythPluginManager::init_plugin(const QString &plugname)

if (!m_dict[newname])
{
m_dict.insert(newname, new MythPlugin(newname));
m_dict.insert(newname, new MythPlugin(newname, plugname));
}

int result = m_dict[newname]->init(MYTH_BINARY_VERSION);
Expand Down Expand Up @@ -318,3 +318,12 @@ void MythPluginManager::DestroyAllPlugins(void)
menuPluginList.clear();
}

QStringList MythPluginManager::EnumeratePlugins(void)
{
QStringList ret;
QHash<QString, MythPlugin*>::const_iterator it = m_dict.begin();
for (; it != m_dict.end(); ++it)
ret << (*it)->getName();
return ret;
}

6 changes: 5 additions & 1 deletion mythtv/libs/libmyth/mythplugin.h
Expand Up @@ -22,7 +22,7 @@ typedef enum {
class MythPlugin : public QLibrary
{
public:
MythPlugin(const QString &);
MythPlugin(const QString &, const QString &);
virtual ~MythPlugin();

// This method will call the mythplugin_init() function of the library.
Expand All @@ -48,6 +48,8 @@ class MythPlugin : public QLibrary
int getPosition() { return position; }
void setPosition(int pos) { position = pos; }

QString getName(void) { return m_plugName; }

// mainmenu plugins, probably should separate out

// setup the plugin -- returns how often (in ms) the plugin wants updated
Expand All @@ -59,6 +61,7 @@ class MythPlugin : public QLibrary
private:
bool enabled;
int position;
QString m_plugName;
};

// this should only be instantiated through MythContext.
Expand All @@ -77,6 +80,7 @@ class MPUBLIC MythPluginManager
MythPlugin *GetMenuPlugin(const QString &plugname);
MythPlugin *GetMenuPluginAt(int pos);

QStringList EnumeratePlugins(void);
void DestroyAllPlugins();

private:
Expand Down
2 changes: 1 addition & 1 deletion mythtv/libs/libmythbase/mythversion.h
Expand Up @@ -12,7 +12,7 @@
/// Update this whenever the plug-in API changes.
/// Including changes in the libmythbase, libmyth, libmythtv, libmythav* and
/// libmythui class methods used by plug-ins.
#define MYTH_BINARY_VERSION "0.25.20111111-1"
#define MYTH_BINARY_VERSION "0.25.20111116-1"

/** \brief Increment this whenever the MythTV network protocol changes.
*
Expand Down
5 changes: 5 additions & 0 deletions mythtv/libs/libmythui/mythmainwindow.cpp
Expand Up @@ -1815,6 +1815,11 @@ bool MythMainWindow::DestinationExists(const QString& destination) const
return (d->destinationMap.count(destination) > 0) ? true : false;
}

QStringList MythMainWindow::EnumerateDestinations(void) const
{
return d->destinationMap.keys();
}

void MythMainWindow::RegisterMediaPlugin(const QString &name,
const QString &desc,
MediaPlayCallback fn)
Expand Down
1 change: 1 addition & 0 deletions mythtv/libs/libmythui/mythmainwindow.h
Expand Up @@ -81,6 +81,7 @@ class MUI_PUBLIC MythMainWindow : public QWidget

void JumpTo(const QString &destination, bool pop = true);
bool DestinationExists(const QString &destination) const;
QStringList EnumerateDestinations(void) const;

bool IsExitingToMain(void) const;

Expand Down
45 changes: 23 additions & 22 deletions mythtv/programs/mythfrontend/main.cpp
Expand Up @@ -1605,24 +1605,6 @@ int main(int argc, char **argv)
pmanager = new MythPluginManager();
gContext->SetPluginManager(pmanager);

if (cmdline.toBool("runplugin"))
{
if (!pmanager->run_plugin(cmdline.toString("runplugin")) ||
!pmanager->run_plugin("myth" + cmdline.toString("runplugin")))
{
qApp->exec();
return GENERIC_EXIT_OK;
}

LOG(VB_GENERAL, LOG_ERR,
QString("Invalid plugin name supplied on command line: '%1'")
.arg(cmdline.toString("runplugin")));
// TODO: list available plugins
// will require new method in MythPluginManager to enumerate
// registered plugins
return GENERIC_EXIT_INVALID_CMDLINE;
}

MediaMonitor *mon = MediaMonitor::GetMediaMonitor();
if (mon)
{
Expand Down Expand Up @@ -1675,7 +1657,26 @@ int main(int argc, char **argv)
PreviewGeneratorQueue::CreatePreviewGeneratorQueue(
PreviewGenerator::kRemote, 50, 60);

if (cmdline.toBool("jumppoint"))
if (cmdline.toBool("runplugin"))
{
QStringList plugins = pmanager->EnumeratePlugins();

if (plugins.contains(cmdline.toString("runplugin")))
pmanager->run_plugin(cmdline.toString("runplugin"));
else if (plugins.contains("myth" + cmdline.toString("runplugin")))
pmanager->run_plugin("myth" + cmdline.toString("runplugin"));
else
{
LOG(VB_GENERAL, LOG_ERR,
QString("Invalid plugin name supplied on command line: '%1'")
.arg(cmdline.toString("runplugin")));
LOG(VB_GENERAL, LOG_ERR,
QString("Available plugins: %1")
.arg(plugins.join(", ")));
return GENERIC_EXIT_INVALID_CMDLINE;
}
}
else if (cmdline.toBool("jumppoint"))
{
MythMainWindow *mmw = GetMythMainWindow();

Expand All @@ -1686,9 +1687,9 @@ int main(int argc, char **argv)
LOG(VB_GENERAL, LOG_ERR,
QString("Invalid jump point supplied on the command line: %1")
.arg(cmdline.toString("jumppoint")));
// TODO: list available jump points
// will require new method from MythMainWindow to enumerate
// registered points
LOG(VB_GENERAL, LOG_ERR,
QString("Available jump points: %2")
.arg(mmw->EnumerateDestinations().join(", ")));
return GENERIC_EXIT_INVALID_CMDLINE;
}
}
Expand Down

0 comments on commit ca52816

Please sign in to comment.