Building Plugins:HelloMyth
Outdated: The information on this page may no longer be relevant to the current release of MythTV, 34.0. Please consider helping to update it. This page was last modified on 2009-10-21.
Contents
Creating Your First Plugin: Hello Myth
This is a really simple skeleton plugin that doesn't do anything. It'll show you what is absolutely necessary to create a plugin, then you can expand on that by dissecting others.
As a disclaimer, I am also very new to plugin development and so please correct me where I might be wrong.
To start, download the mythplugin directory from SVN and create the following directory tree within its:
svn co http://svn.mythtv.org/svn/trunk/mythplugins mkdir -p mythplugins/mythhello/mythhello
You will also need to install some development tools if you don't already have them (qmake-qt4 for newer mythtv, or qmake for older versions). For example:
sudo apt-get install qt4-qmake
mythhello.pro Files
The *.pro files are used by qmake to create the Makefiles.
1) Create a file called mythhello.pro in the first mythhello directory:
TEMPLATE = subdirs # Directories SUBDIRS = mythhello
"mythhello" refers to the second mythhello directory.
2) Create another file called mythhello.pro in the second mythhello (mythplugins/mythhello/mythhello/mythhello.pro) directory
include ( ../../mythconfig.mak ) include ( ../../settings.pro ) TEMPLATE = lib CONFIG += plugin thread TARGET = mythhello target.path = $${LIBDIR}/mythtv/plugins INSTALLS += target uifiles.path = $${PREFIX}/share/mythtv/themes/default uifiles.files = hello-ui.xml installfiles.path = $${PREFIX}/share/mythtv installfiles.files = hello-ui.xml INSTALLS += uifiles # Input HEADERS += mythhello.h SOURCES += main.cpp mythhello.cpp macx { QMAKE_LFLAGS += -flat_namespace -undefined suppress }
The following items are specific to your plugin: 'uifiles.files', 'installfiles.files', 'HEADERS', 'SOURCES'. Be sure that $${LIBDIR} and $${PREFIX} are set in mythplugins/mythconfig.mak to be the mythtv install prefix and library directory. Mine are set to:
PREFIX=/usr/ LIBDIR=/usr/lib/
CPP Files
Now we create the cpp/h files which should be put in mythplugins/mythhello/mythhello/.
main.cpp
Here's the main file that takes care of initializing, running and destructing the pluigin:
#ifndef MAIN_CPP #define MAIN_CPP using namespace std; #include "mythhello.h" #include <mythtv/mythcontext.h> #include <mythtv/mythdbcon.h> #include <mythtv/lcddevice.h> #include <mythtv/libmythui/myththemedmenu.h> extern "C" { int mythplugin_init(const char *libversion); int mythplugin_run(void); int mythplugin_config(void); } int mythplugin_init(const char *libversion) { if (!gContext->TestPopupVersion("mythhello", libversion, MYTH_BINARY_VERSION)) return -1; return 0; } int mythplugin_run (void) { gContext->addCurrentLocation("mythhello"); MythHello hello(gContext->GetMainWindow(), "hello", "hello-"); hello.exec(); gContext->removeCurrentLocation(); return 1; } int mythplugin_config (void) { return 0; } #endif
mythhello.h
#ifndef MYTHHELLO_H #define MYTHHELLO_H #include <mythtv/uitypes.h> #include <mythtv/uilistbtntype.h> #include <mythtv/xmlparse.h> #include <mythtv/mythdialogs.h> class MythHello : virtual public MythThemedDialog { public: MythHello(MythMainWindow *parent, QString windowName, QString themeFilename, const char *name = 0); ~MythHello(); }; #endif
mythhello.cpp
#ifndef MYTHHELLO_CPP #define MYTHHELLO_CPP /* QT includes */ #include <qnamespace.h> #include <qstringlist.h> #include <qapplication.h> #include <qbuttongroup.h> /* MythTV includes */ #include <mythtv/mythcontext.h> #include <mythtv/mythdialogs.h> using namespace std; #include "mythhello.h" MythHello::MythHello(MythMainWindow *parent, QString windowName, QString themeFilename, const char *name) : MythThemedDialog(parent, windowName, themeFilename, name) { } MythHello::~MythHello() { } #endif
The UI File
What would a plugin be without a UI? Now create hello-ui.xml and put it in mythplugins/mythhello/mythhello/.
<?xml version="1.0" encoding="utf-8"?> <mythuitheme> <window name="hello"> <font name="title" face="Arial"> <color>#ffffff</color> <size>24</size> <bold>yes</bold> </font> <container name="hello"> <area>20,20,780,450</area> <textarea name="title" draworder="1" align="center"> <font>title</font> <area>0,0,780,40</area> <value>Hello MythTV!</value> </textarea> </container> </window> </mythuitheme>
Building
Go to the top mythhello directory (mythplugins/mythhello) and run these commands:
su qmake make make install
Make sure everything compiled OK and the files where copied to your mythtv installation directories.
Adding MythHello to your Menus
As a final step you have to add your plugin to the main MythTv menu -- in my case /usr/share/mythtv/mainmenu.xml. Add the following anywhere in the XML file between the <mythmenu> root tag:
<button> <type>HELLO_MYTH</type> <text>Hello Myth</text> <action>PLUGIN mythhello</action> </button>
Finishing Up
Now restart MythFrontend and you should see a 'Hello Myth' button on the main menu.
Good Luck
- Mozmonkey