Difference between revisions of "Building Plugins:HelloMyth"

From MythTV Official Wiki
Jump to: navigation, search
Line 63: Line 63:
 
=== CPP Files ===
 
=== CPP Files ===
  
Now we create the CPP/H files:
+
Now we create the cpp/h files which should be put in mythplugins/mythhello/mythhello/.
  
 
==== main.cpp ====
 
==== main.cpp ====
Line 175: Line 175:
 
#endif
 
#endif
 
</pre>
 
</pre>
 +
 +
=== The UI File ===
 +
 +
What would a plugin be without a UI?  Now create hello-ui.xml and put it in mythplugins/mythhello/mythhello/.
 +
 +
<pre>
 +
<?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>
 +
</pre>
 +
 +
=== Building ===
 +
 +
Go to the top mythhello directory (mythplugins/mythhello) and run these commands:
 +
 +
<pre>
 +
su
 +
qmake
 +
make
 +
make install
 +
</pre>
 +
 +
Make sure everything compiled OK and the files are placed with your mythtv installation files.
 +
 +
=== 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/themes/classic/tvmenu.xml.  Add the following anywhere in the XML file between the <mythmenu> root tag:
 +
 +
<pre>
 +
<button>
 +
  <type>HELLO_MYTH</type>
 +
  <text>Hello Myth</text>
 +
  <action>PLUGIN mythhello</action>
 +
</button>
 +
</pre>
 +
 +
=== Finishing Up ===
 +
 +
Now restart MythFrontend and you should see a Hello Myth button on the main menu.
 +
 +
Good Luck

Revision as of 05:20, 22 January 2007

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 disecting 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. Now create the following directory tree within the mythplugin directory:

mythplugin/
  mythhello/
    mythhello/

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 = <strong>mythhello</strong>

"mythhello" refers to the second mythhello directory.

2) Create another file called mythhello.pro in the second mythhello 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 plugin main file:

#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 MYTHEZRECORD_H
#define MYTHEZRECORD_H

#include <mythtv/uitypes.h>
#include <mythtv/uilistbtntype.h>
#include <mythtv/xmlparse.h>
#include <mythtv/mythdialogs.h>


/**
 * @class MythEzRecord
 * @brief The myth ezrecord configuration class.
 */
class MythHello : virtual public MythThemedDialog
{


public:

    MythHello(MythMainWindow *parent, QString windowName,
           QString themeFilename, const char *name = 0);
    ~MythHello();

};


#endif

mythhello.h

#ifndef MYTHEZRECORD_CPP
#define MYTHEZRECORD_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 are placed with your mythtv installation files.

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/themes/classic/tvmenu.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