Code cleanup

Use GNU formatter from Eclipse.
This commit is contained in:
Stéphane Cerveau 2017-05-31 21:35:10 +02:00
parent 606b1bb3eb
commit 2d75a32dd0
21 changed files with 2718 additions and 2812 deletions

View file

@ -1,13 +1,15 @@
#include "CustomMenuAction.h" #include "CustomMenuAction.h"
CustomMenuAction::CustomMenuAction(const QString& displayName, QObject * parent) CustomMenuAction::CustomMenuAction (const QString& displayName,
:QAction(displayName, parent) QObject * parent)
, m_name(displayName) : QAction (displayName, parent),
m_name (displayName)
{ {
} }
CustomMenuAction::CustomMenuAction(const QString& displayName, const QString& name, QObject * parent) CustomMenuAction::CustomMenuAction (const QString& displayName,
:QAction(displayName, parent) const QString& name, QObject * parent)
, m_name(name) : QAction (displayName, parent),
m_name (name)
{ {
} }

View file

@ -1,14 +1,12 @@
#ifndef CUSTOM_MENU_ACTION_H_ #ifndef CUSTOM_MENU_ACTION_H_
#define CUSTOM_MENU_ACTION_H_ #define CUSTOM_MENU_ACTION_H_
#include <QAction> #include <QAction>
class CustomMenuAction: public QAction class CustomMenuAction: public QAction
{ {
public: public:
CustomMenuAction(const QString& displayName, QObject * parent); CustomMenuAction(const QString& displayName, QObject * parent);
CustomMenuAction(const QString& displayName, const QString& name, QObject * parent); CustomMenuAction(const QString& displayName, const QString& name, QObject * parent);
QString getName() {return m_name;} QString getName() {return m_name;}
@ -17,6 +15,4 @@ private:
QString m_name; QString m_name;
}; };
#endif //CUSTOM_MENU_ACTION_H_ #endif //CUSTOM_MENU_ACTION_H_

View file

@ -5,14 +5,15 @@
#define COMPANY_NAME "virinext" #define COMPANY_NAME "virinext"
#define APPLICATION_NAME "pipeviz" #define APPLICATION_NAME "pipeviz"
void CustomSettings::saveLastIODirectory(const QString &name) void
CustomSettings::saveLastIODirectory (const QString &name)
{ {
QSettings settings (COMPANY_NAME, APPLICATION_NAME); QSettings settings (COMPANY_NAME, APPLICATION_NAME);
settings.setValue ("last_directory", name); settings.setValue ("last_directory", name);
} }
QString
QString CustomSettings::lastIODirectory() CustomSettings::lastIODirectory ()
{ {
QSettings settings (COMPANY_NAME, APPLICATION_NAME); QSettings settings (COMPANY_NAME, APPLICATION_NAME);
QString res = settings.value ("last_directory").toString (); QString res = settings.value ("last_directory").toString ();
@ -23,15 +24,15 @@ QString CustomSettings::lastIODirectory()
return res; return res;
} }
void
void CustomSettings::saveMainWindowGeometry(const QByteArray &geometry) CustomSettings::saveMainWindowGeometry (const QByteArray &geometry)
{ {
QSettings settings (COMPANY_NAME, APPLICATION_NAME); QSettings settings (COMPANY_NAME, APPLICATION_NAME);
settings.setValue ("geometry", geometry); settings.setValue ("geometry", geometry);
} }
QByteArray
QByteArray CustomSettings::mainWindowGeometry() CustomSettings::mainWindowGeometry ()
{ {
QSettings settings (COMPANY_NAME, APPLICATION_NAME); QSettings settings (COMPANY_NAME, APPLICATION_NAME);
return settings.value ("geometry").toByteArray (); return settings.value ("geometry").toByteArray ();

View file

@ -4,7 +4,6 @@
#include <QString> #include <QString>
#include <QByteArray> #include <QByteArray>
namespace CustomSettings namespace CustomSettings
{ {
void saveLastIODirectory(const QString &name); void saveLastIODirectory(const QString &name);
@ -14,6 +13,4 @@ namespace CustomSettings
QByteArray mainWindowGeometry(); QByteArray mainWindowGeometry();
} }
#endif #endif

View file

@ -11,9 +11,10 @@
#include <gst/gst.h> #include <gst/gst.h>
ElementProperties::ElementProperties(QSharedPointer<GraphManager> pGraph, const char *name, ElementProperties::ElementProperties (QSharedPointer<GraphManager> pGraph,
QWidget *parent, Qt::WindowFlags flags): const char *name, QWidget *parent,
QWidget(parent, flags), Qt::WindowFlags flags)
: QWidget (parent, flags),
m_pGraphManager (pGraph), m_pGraphManager (pGraph),
m_name (name) m_name (name)
{ {
@ -22,21 +23,20 @@ m_name(name)
create (); create ();
} }
void
void ElementProperties::addParamEnum(GParamSpec *param, GstElement *element, QGridLayout *play) ElementProperties::addParamEnum (GParamSpec *param, GstElement *element,
QGridLayout *play)
{ {
GValue value = { 0 }; GValue value = { 0 };
g_value_init (&value, param->value_type); g_value_init (&value, param->value_type);
if (param->flags & G_PARAM_READABLE) if (param->flags & G_PARAM_READABLE)
g_object_get_property (G_OBJECT (element), param->name, &value); g_object_get_property (G_OBJECT (element), param->name, &value);
else else {
{
const GValue *valueDef = g_param_spec_get_default_value (param); const GValue *valueDef = g_param_spec_get_default_value (param);
g_value_copy (valueDef, &value); g_value_copy (valueDef, &value);
} }
QString propertyName = g_param_spec_get_name (param); QString propertyName = g_param_spec_get_name (param);
int propertyValue; int propertyValue;
@ -49,8 +49,7 @@ void ElementProperties::addParamEnum(GParamSpec *param, GstElement *element, QGr
QComboBox *pcomBox = new QComboBox; QComboBox *pcomBox = new QComboBox;
for(std::size_t i=0; i<penumSpec -> enum_class -> n_values; i++) for (std::size_t i = 0; i < penumSpec->enum_class->n_values; i++) {
{
QVariant var (penumSpec->enum_class->values[i].value); QVariant var (penumSpec->enum_class->values[i].value);
QString valueName = penumSpec->enum_class->values[i].value_name; QString valueName = penumSpec->enum_class->values[i].value_name;
@ -60,31 +59,26 @@ void ElementProperties::addParamEnum(GParamSpec *param, GstElement *element, QGr
pcomBox->setCurrentIndex (i); pcomBox->setCurrentIndex (i);
} }
int row = play->rowCount (); int row = play->rowCount ();
play->addWidget (new QLabel (propertyName), row, 0); play->addWidget (new QLabel (propertyName), row, 0);
play->addWidget (pcomBox, row, 1); play->addWidget (pcomBox, row, 1);
m_values.insert (propertyName, pcomBox); m_values.insert (propertyName, pcomBox);
} }
void
void ElementProperties::addParamFlags(GParamSpec *param, GstElement *element, QGridLayout *play) ElementProperties::addParamFlags (GParamSpec *param, GstElement *element,
QGridLayout *play)
{ {
GValue value = { 0 }; GValue value = { 0 };
g_value_init (&value, param->value_type); g_value_init (&value, param->value_type);
if (param->flags & G_PARAM_READABLE) if (param->flags & G_PARAM_READABLE)
g_object_get_property (G_OBJECT (element), param->name, &value); g_object_get_property (G_OBJECT (element), param->name, &value);
else else {
{
const GValue *valueDef = g_param_spec_get_default_value (param); const GValue *valueDef = g_param_spec_get_default_value (param);
g_value_copy (valueDef, &value); g_value_copy (valueDef, &value);
} }
QString propertyName = g_param_spec_get_name (param); QString propertyName = g_param_spec_get_name (param);
int propertyValue; int propertyValue;
@ -97,8 +91,7 @@ void ElementProperties::addParamFlags(GParamSpec *param, GstElement *element, QG
QComboBox *pcomBox = new QComboBox; QComboBox *pcomBox = new QComboBox;
for(std::size_t i=0; i<pflagsSpec -> flags_class -> n_values; i++) for (std::size_t i = 0; i < pflagsSpec->flags_class->n_values; i++) {
{
QVariant var (pflagsSpec->flags_class->values[i].value); QVariant var (pflagsSpec->flags_class->values[i].value);
QString valueName = pflagsSpec->flags_class->values[i].value_name; QString valueName = pflagsSpec->flags_class->values[i].value_name;
@ -108,7 +101,6 @@ void ElementProperties::addParamFlags(GParamSpec *param, GstElement *element, QG
pcomBox->setCurrentIndex (i); pcomBox->setCurrentIndex (i);
} }
int row = play->rowCount (); int row = play->rowCount ();
play->addWidget (new QLabel (propertyName), row, 0); play->addWidget (new QLabel (propertyName), row, 0);
@ -118,9 +110,9 @@ void ElementProperties::addParamFlags(GParamSpec *param, GstElement *element, QG
m_values.insert (propertyName, pcomBox); m_values.insert (propertyName, pcomBox);
} }
void
ElementProperties::addParamSimple (GParamSpec *param, GstElement *element,
void ElementProperties::addParamSimple(GParamSpec *param, GstElement *element, QGridLayout *play) QGridLayout *play)
{ {
bool readOnly = true; bool readOnly = true;
@ -132,85 +124,69 @@ void ElementProperties::addParamSimple(GParamSpec *param, GstElement *element, Q
g_value_init (&value, param->value_type); g_value_init (&value, param->value_type);
if (param->flags & G_PARAM_READABLE) if (param->flags & G_PARAM_READABLE)
g_object_get_property (G_OBJECT (element), param->name, &value); g_object_get_property (G_OBJECT (element), param->name, &value);
else else {
{
const GValue *valueDef = g_param_spec_get_default_value (param); const GValue *valueDef = g_param_spec_get_default_value (param);
g_value_copy (valueDef, &value); g_value_copy (valueDef, &value);
} }
QString propertyName = g_param_spec_get_name (param); QString propertyName = g_param_spec_get_name (param);
QString propertyValue; QString propertyValue;
bool skip = false; bool skip = false;
switch (G_VALUE_TYPE (&value)) switch (G_VALUE_TYPE (&value)) {
{ case G_TYPE_STRING: {
case G_TYPE_STRING:
{
const char *string_val = g_value_get_string (&value); const char *string_val = g_value_get_string (&value);
propertyValue = string_val; propertyValue = string_val;
break; break;
} }
case G_TYPE_BOOLEAN: case G_TYPE_BOOLEAN: {
{
gboolean bool_val = g_value_get_boolean (&value); gboolean bool_val = g_value_get_boolean (&value);
propertyValue = QString::number (bool_val); propertyValue = QString::number (bool_val);
break; break;
} }
case G_TYPE_ULONG: case G_TYPE_ULONG: {
{
propertyValue = QString::number (g_value_get_ulong (&value)); propertyValue = QString::number (g_value_get_ulong (&value));
break; break;
} }
case G_TYPE_LONG: case G_TYPE_LONG: {
{
propertyValue = QString::number (g_value_get_long (&value)); propertyValue = QString::number (g_value_get_long (&value));
break; break;
} }
case G_TYPE_UINT: case G_TYPE_UINT: {
{
propertyValue = QString::number (g_value_get_uint (&value)); propertyValue = QString::number (g_value_get_uint (&value));
break; break;
} }
case G_TYPE_INT: case G_TYPE_INT: {
{
propertyValue = QString::number (g_value_get_int (&value)); propertyValue = QString::number (g_value_get_int (&value));
break; break;
} }
case G_TYPE_UINT64: case G_TYPE_UINT64: {
{
propertyValue = QString::number (g_value_get_uint64 (&value)); propertyValue = QString::number (g_value_get_uint64 (&value));
break; break;
} }
case G_TYPE_INT64: case G_TYPE_INT64: {
{
propertyValue = QString::number (g_value_get_int64 (&value)); propertyValue = QString::number (g_value_get_int64 (&value));
break; break;
} }
case G_TYPE_FLOAT: case G_TYPE_FLOAT: {
{
propertyValue = QString::number (g_value_get_float (&value)); propertyValue = QString::number (g_value_get_float (&value));
break; break;
} }
case G_TYPE_DOUBLE: case G_TYPE_DOUBLE: {
{
propertyValue = QString::number (g_value_get_double (&value)); propertyValue = QString::number (g_value_get_double (&value));
break; break;
} }
case G_TYPE_CHAR: case G_TYPE_CHAR: {
{
propertyValue = QString::number (g_value_get_char (&value)); propertyValue = QString::number (g_value_get_char (&value));
break; break;
} }
case G_TYPE_UCHAR: case G_TYPE_UCHAR: {
{
propertyValue = QString::number (g_value_get_uchar (&value)); propertyValue = QString::number (g_value_get_uchar (&value));
break; break;
} }
default: default: {
{
skip = true; skip = true;
qDebug () << "property " << propertyName << " not supported"; qDebug () << "property " << propertyName << " not supported";
break; break;
@ -230,10 +206,11 @@ void ElementProperties::addParamSimple(GParamSpec *param, GstElement *element, Q
ple->setReadOnly (true); ple->setReadOnly (true);
} }
void
void ElementProperties::create() ElementProperties::create ()
{ {
GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraphManager -> m_pGraph), m_name.toStdString().c_str()); GstElement *element = gst_bin_get_by_name (
GST_BIN (m_pGraphManager->m_pGraph), m_name.toStdString ().c_str ());
if (!element) if (!element)
return; return;
@ -246,8 +223,7 @@ void ElementProperties::create()
prop_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element), prop_specs = g_object_class_list_properties (G_OBJECT_GET_CLASS (element),
&num_props); &num_props);
for(std::size_t i = 0; i<num_props; i++) for (std::size_t i = 0; i < num_props; i++) {
{
GParamSpec *param = prop_specs[i]; GParamSpec *param = prop_specs[i];
if (G_IS_PARAM_SPEC_ENUM (param)) if (G_IS_PARAM_SPEC_ENUM (param))
@ -272,7 +248,6 @@ void ElementProperties::create()
QPushButton *pcmdOk = new QPushButton ("OK"); QPushButton *pcmdOk = new QPushButton ("OK");
QPushButton *pcmdCancel = new QPushButton ("Cancel"); QPushButton *pcmdCancel = new QPushButton ("Cancel");
phblay->addStretch (1); phblay->addStretch (1);
phblay->addWidget (pcmdApply); phblay->addWidget (pcmdApply);
phblay->addWidget (pcmdCancel); phblay->addWidget (pcmdCancel);
@ -280,7 +255,8 @@ void ElementProperties::create()
pvblay->addLayout (phblay); pvblay->addLayout (phblay);
QObject::connect(pcmdApply, SIGNAL(clicked()), this, SLOT(applyClicked())); QObject::connect (pcmdApply, SIGNAL (clicked ()), this,
SLOT (applyClicked ()));
QObject::connect (pcmdCancel, SIGNAL (clicked ()), this, SLOT (close ())); QObject::connect (pcmdCancel, SIGNAL (clicked ()), this, SLOT (close ()));
QObject::connect (pcmdOk, SIGNAL (clicked ()), this, SLOT (okClicked ())); QObject::connect (pcmdOk, SIGNAL (clicked ()), this, SLOT (okClicked ()));
@ -291,23 +267,22 @@ void ElementProperties::create()
} }
void ElementProperties::applyClicked() void
ElementProperties::applyClicked ()
{ {
GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraphManager -> m_pGraph), GstElement *element = gst_bin_get_by_name (
m_name.toStdString().c_str()); GST_BIN (m_pGraphManager->m_pGraph), m_name.toStdString ().c_str ());
if (!element) if (!element)
return; return;
QMap<QString, QWidget *>::iterator itr = m_values.begin (); QMap<QString, QWidget *>::iterator itr = m_values.begin ();
for(;itr != m_values.end(); itr++) for (; itr != m_values.end (); itr++) {
{ GParamSpec *param = g_object_class_find_property (
GParamSpec *param = g_object_class_find_property(G_OBJECT_GET_CLASS (element), G_OBJECT_GET_CLASS (element), itr.key ().toStdString ().c_str ());
itr.key().toStdString().c_str());
if(!param) if (!param) {
{
qDebug () << "problem with setting " << itr.key () << " property"; qDebug () << "problem with setting " << itr.key () << " property";
continue; continue;
} }
@ -319,8 +294,7 @@ void ElementProperties::applyClicked()
if (dynamic_cast<QLineEdit *> (itr.value ())) if (dynamic_cast<QLineEdit *> (itr.value ()))
valStr = ((QLineEdit *) itr.value ())->text (); valStr = ((QLineEdit *) itr.value ())->text ();
else if(dynamic_cast<QComboBox *>(itr.value())) else if (dynamic_cast<QComboBox *> (itr.value ())) {
{
QComboBox *pcomBox = (QComboBox *) itr.value (); QComboBox *pcomBox = (QComboBox *) itr.value ();
int val = pcomBox->itemData (pcomBox->currentIndex ()).toInt (); int val = pcomBox->itemData (pcomBox->currentIndex ()).toInt ();
valStr = QString::number (val); valStr = QString::number (val);
@ -329,92 +303,76 @@ void ElementProperties::applyClicked()
std::string tmpStr = itr.key ().toStdString (); std::string tmpStr = itr.key ().toStdString ();
const char *propName = tmpStr.c_str (); const char *propName = tmpStr.c_str ();
if(G_IS_PARAM_SPEC_ENUM(param) || G_IS_PARAM_SPEC_FLAGS(param)) if (G_IS_PARAM_SPEC_ENUM (param) || G_IS_PARAM_SPEC_FLAGS (param)) {
{ if (dynamic_cast<QComboBox *> (itr.value ())) {
if(dynamic_cast<QComboBox *>(itr.value()))
{
QComboBox *pcomBox = (QComboBox *) itr.value (); QComboBox *pcomBox = (QComboBox *) itr.value ();
int val = pcomBox->itemData (pcomBox->currentIndex ()).toInt (); int val = pcomBox->itemData (pcomBox->currentIndex ()).toInt ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
} }
} }
else else {
{ switch (param->value_type) {
switch (param -> value_type) case G_TYPE_STRING: {
{ g_object_set (G_OBJECT (element), propName,
case G_TYPE_STRING: valStr.toStdString ().c_str (), NULL);
{
g_object_set(G_OBJECT(element), propName, valStr.toStdString().c_str(), NULL);
break; break;
} }
case G_TYPE_BOOLEAN: case G_TYPE_BOOLEAN: {
{
gboolean val = valStr.toInt (); gboolean val = valStr.toInt ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_ULONG: case G_TYPE_ULONG: {
{
gulong val = valStr.toULong (); gulong val = valStr.toULong ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_LONG: case G_TYPE_LONG: {
{
glong val = valStr.toLong (); glong val = valStr.toLong ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_UINT: case G_TYPE_UINT: {
{
guint val = valStr.toUInt (); guint val = valStr.toUInt ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_INT: case G_TYPE_INT: {
{
gint val = valStr.toInt (); gint val = valStr.toInt ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_UINT64: case G_TYPE_UINT64: {
{
guint64 val = valStr.toULongLong (); guint64 val = valStr.toULongLong ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_INT64: case G_TYPE_INT64: {
{
gint64 val = valStr.toLongLong (); gint64 val = valStr.toLongLong ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_FLOAT: case G_TYPE_FLOAT: {
{
gfloat val = valStr.toFloat (); gfloat val = valStr.toFloat ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_DOUBLE: case G_TYPE_DOUBLE: {
{
gdouble val = valStr.toDouble (); gdouble val = valStr.toDouble ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_CHAR: case G_TYPE_CHAR: {
{
gchar val = valStr.toInt (); gchar val = valStr.toInt ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_UCHAR: case G_TYPE_UCHAR: {
{
guchar val = valStr.toUInt (); guchar val = valStr.toUInt ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
default: default: {
{
qDebug () << "property " << itr.key () << " not supported"; qDebug () << "property " << itr.key () << " not supported";
break; break;
} }
@ -425,13 +383,14 @@ void ElementProperties::applyClicked()
gst_object_unref (element); gst_object_unref (element);
delete layout (); delete layout ();
qDeleteAll(children()); qDeleteAll (
children ());
create (); create ();
} }
void ElementProperties::okClicked() void
ElementProperties::okClicked ()
{ {
applyClicked (); applyClicked ();
close (); close ();

View file

@ -17,7 +17,6 @@ public:
ElementProperties(QSharedPointer<GraphManager> pGraphManager, const char *name, ElementProperties(QSharedPointer<GraphManager> pGraphManager, const char *name,
QWidget *parent = 0, Qt::WindowFlags flags = 0); QWidget *parent = 0, Qt::WindowFlags flags = 0);
private slots: private slots:
void applyClicked(); void applyClicked();
void okClicked(); void okClicked();
@ -33,5 +32,4 @@ private:
void addParamFlags(GParamSpec *value, GstElement *element, QGridLayout *play); void addParamFlags(GParamSpec *value, GstElement *element, QGridLayout *play);
}; };
#endif #endif

View file

@ -21,20 +21,19 @@
#define PAD_SIZE 8 #define PAD_SIZE 8
#define PAD_SIZE_ACTION 16 #define PAD_SIZE_ACTION 16
GraphDisplay::GraphDisplay (QWidget *parent, Qt::WindowFlags f)
GraphDisplay::GraphDisplay(QWidget *parent, Qt::WindowFlags f): : QWidget (parent, f)
QWidget(parent, f)
{ {
setFocusPolicy (Qt::WheelFocus); setFocusPolicy (Qt::WheelFocus);
setMouseTracking (true); setMouseTracking (true);
} }
ElementInfo* GraphDisplay::getElement(std::size_t elementId) ElementInfo*
GraphDisplay::getElement (std::size_t elementId)
{ {
ElementInfo* element = NULL; ElementInfo* element = NULL;
std::size_t i = 0; std::size_t i = 0;
for(; i<m_info.size(); i++) for (; i < m_info.size (); i++) {
{
if (m_info[i].m_id == elementId) { if (m_info[i].m_id == elementId) {
element = &m_info[i]; element = &m_info[i];
break; break;
@ -43,7 +42,8 @@ ElementInfo* GraphDisplay::getElement(std::size_t elementId)
return element; return element;
} }
PadInfo* GraphDisplay::getPad(std::size_t elementId, std::size_t padId) PadInfo*
GraphDisplay::getPad (std::size_t elementId, std::size_t padId)
{ {
PadInfo* pad = NULL; PadInfo* pad = NULL;
ElementInfo* element = getElement (elementId); ElementInfo* element = getElement (elementId);
@ -58,17 +58,14 @@ PadInfo* GraphDisplay::getPad(std::size_t elementId, std::size_t padId)
return pad; return pad;
} }
void GraphDisplay::updateDisplayInfoIds() void
{ GraphDisplay::updateDisplayInfoIds ()
for(std::size_t i=0; i<m_info.size(); i++)
{
for(std::size_t j=0; j<m_displayInfo.size(); j++)
{
if(m_info[i].m_name == m_displayInfo[j].m_name)
{ {
for (std::size_t i = 0; i < m_info.size (); i++) {
for (std::size_t j = 0; j < m_displayInfo.size (); j++) {
if (m_info[i].m_name == m_displayInfo[j].m_name) {
m_displayInfo[j].m_id = m_info[i].m_id; m_displayInfo[j].m_id = m_info[i].m_id;
for(std::size_t k=0; k<m_displayInfo.size(); k++) for (std::size_t k = 0; k < m_displayInfo.size (); k++) {
{
if (k != j && m_displayInfo[j].m_id == m_displayInfo[k].m_id) if (k != j && m_displayInfo[j].m_id == m_displayInfo[k].m_id)
m_displayInfo[k].m_id = (size_t) -1; m_displayInfo[k].m_id = (size_t) -1;
} }
@ -77,47 +74,41 @@ void GraphDisplay::updateDisplayInfoIds()
} }
} }
void GraphDisplay::update(const std::vector <ElementInfo> &info) void
GraphDisplay::update (const std::vector<ElementInfo> &info)
{ {
bool needUpdate = false; bool needUpdate = false;
if (m_info.size () != info.size ()) if (m_info.size () != info.size ())
needUpdate = true; needUpdate = true;
if(!needUpdate) if (!needUpdate) {
{ for (std::size_t i = 0; i < info.size (); i++) {
for(std::size_t i=0; i<info.size(); i++)
{
std::size_t j = 0; std::size_t j = 0;
for(; j<m_info.size(); j++) for (; j < m_info.size (); j++) {
{
if (info[i].m_name == m_info[j].m_name) if (info[i].m_name == m_info[j].m_name)
break; break;
} }
if(j == m_info.size()) if (j == m_info.size ()) {
{
needUpdate = true; needUpdate = true;
break; break;
} }
if(info[i].m_pads != m_info[j].m_pads) if (info[i].m_pads != m_info[j].m_pads) {
{
needUpdate = true; needUpdate = true;
break; break;
} }
if(info[i].m_connections != m_info[j].m_connections) if (info[i].m_connections != m_info[j].m_connections) {
{
needUpdate = true; needUpdate = true;
break; break;
} }
} }
} }
if(needUpdate) if (needUpdate) {
{
m_info = info; m_info = info;
updateDisplayInfoIds (); updateDisplayInfoIds ();
calculatePositions (); calculatePositions ();
@ -125,12 +116,12 @@ void GraphDisplay::update(const std::vector <ElementInfo> &info)
} }
} }
void GraphDisplay::paintEvent(QPaintEvent *event) void
GraphDisplay::paintEvent (QPaintEvent *event)
{ {
QPainter painter (this); QPainter painter (this);
QPen defaultPen = painter.pen (); QPen defaultPen = painter.pen ();
for(std::size_t i=0; i<m_displayInfo.size(); i++) for (std::size_t i = 0; i < m_displayInfo.size (); i++) {
{
if (m_displayInfo[i].m_isSelected) if (m_displayInfo[i].m_isSelected)
painter.setPen (QPen (Qt::blue)); painter.setPen (QPen (Qt::blue));
@ -138,8 +129,7 @@ void GraphDisplay::paintEvent(QPaintEvent *event)
painter.setPen (defaultPen); painter.setPen (defaultPen);
for(std::size_t j=0; j<m_info[i].m_pads.size(); j++) for (std::size_t j = 0; j < m_info[i].m_pads.size (); j++) {
{
QPoint point = getPadPosition (m_info[i].m_id, m_info[i].m_pads[j].m_id); QPoint point = getPadPosition (m_info[i].m_id, m_info[i].m_pads[j].m_id);
@ -154,19 +144,23 @@ void GraphDisplay::paintEvent(QPaintEvent *event)
QPoint textPos; QPoint textPos;
QRect rect = painter.boundingRect(0, 0, width(), height(), Qt::AlignLeft | Qt::AlignTop, QString(m_info[i].m_pads[j].m_name.c_str())); QRect rect = painter.boundingRect (
0, 0, width (), height (), Qt::AlignLeft | Qt::AlignTop,
QString (m_info[i].m_pads[j].m_name.c_str ()));
if (m_info[i].m_pads[j].m_type == PadInfo::Out) if (m_info[i].m_pads[j].m_type == PadInfo::Out)
textPos = QPoint(point.x() - PAD_SIZE - rect.width(), point.y() + PAD_SIZE / 2); textPos = QPoint (point.x () - PAD_SIZE - rect.width (),
point.y () + PAD_SIZE / 2);
else if (m_info[i].m_pads[j].m_type == PadInfo::In) else if (m_info[i].m_pads[j].m_type == PadInfo::In)
textPos = QPoint (point.x () + PAD_SIZE, point.y () + PAD_SIZE / 2); textPos = QPoint (point.x () + PAD_SIZE, point.y () + PAD_SIZE / 2);
painter.drawText (textPos, QString (m_info[i].m_pads[j].m_name.c_str ())); painter.drawText (textPos, QString (m_info[i].m_pads[j].m_name.c_str ()));
if(m_info[i].m_connections[j].m_elementId != ((size_t)-1) && m_info[i].m_connections[j].m_padId != ((size_t)-1)) if (m_info[i].m_connections[j].m_elementId != ((size_t) -1)
{ && m_info[i].m_connections[j].m_padId != ((size_t) -1)) {
xPos = point.x (); xPos = point.x ();
yPos = point.y (); yPos = point.y ();
point = getPadPosition(m_info[i].m_connections[j].m_elementId, m_info[i].m_connections[j].m_padId); point = getPadPosition (m_info[i].m_connections[j].m_elementId,
m_info[i].m_connections[j].m_padId);
int xPosPeer, yPosPeer; int xPosPeer, yPosPeer;
xPosPeer = point.x (); xPosPeer = point.x ();
@ -177,24 +171,24 @@ void GraphDisplay::paintEvent(QPaintEvent *event)
} }
painter.drawText(m_displayInfo[i].m_rect.topLeft() + QPoint(10, 15), QString(m_displayInfo[i].m_name.c_str())); painter.drawText (m_displayInfo[i].m_rect.topLeft () + QPoint (10, 15),
QString (m_displayInfo[i].m_name.c_str ()));
} }
if(m_moveInfo.m_action == MakeConnect) if (m_moveInfo.m_action == MakeConnect) {
{
painter.drawLine (m_moveInfo.m_position, m_moveInfo.m_startPosition); painter.drawLine (m_moveInfo.m_position, m_moveInfo.m_startPosition);
} }
else if(m_moveInfo.m_action == Select) else if (m_moveInfo.m_action == Select) {
{ if (!m_moveInfo.m_position.isNull ()) {
if(!m_moveInfo.m_position.isNull())
{
painter.setPen (Qt::DashLine); painter.setPen (Qt::DashLine);
painter.drawRect(QRect(m_moveInfo.m_startPosition, m_moveInfo.m_position)); painter.drawRect (
QRect (m_moveInfo.m_startPosition, m_moveInfo.m_position));
} }
} }
} }
GraphDisplay::ElementDisplayInfo GraphDisplay::calculateOnePosition(const ElementInfo &info) GraphDisplay::ElementDisplayInfo
GraphDisplay::calculateOnePosition (const ElementInfo &info)
{ {
ElementDisplayInfo displayInfo; ElementDisplayInfo displayInfo;
displayInfo.m_id = info.m_id; displayInfo.m_id = info.m_id;
@ -207,8 +201,7 @@ GraphDisplay::ElementDisplayInfo GraphDisplay::calculateOnePosition(const Elemen
int numInPads, numOutPads; int numInPads, numOutPads;
numInPads = numOutPads = 0; numInPads = numOutPads = 0;
for(std::size_t j=0; j<info.m_pads.size(); j++) for (std::size_t j = 0; j < info.m_pads.size (); j++) {
{
if (info.m_pads[j].m_type == PadInfo::Out) if (info.m_pads[j].m_type == PadInfo::Out)
numOutPads++; numOutPads++;
else if (info.m_pads[j].m_type == PadInfo::In) else if (info.m_pads[j].m_type == PadInfo::In)
@ -223,15 +216,12 @@ GraphDisplay::ElementDisplayInfo GraphDisplay::calculateOnePosition(const Elemen
QRect rect (curX, curY, width, height); QRect rect (curX, curY, width, height);
while(true) while (true) {
{
rect = QRect (curX, curY, width, height); rect = QRect (curX, curY, width, height);
QRect rectTest (curX, curY - 15, width + 15, height + 15); QRect rectTest (curX, curY - 15, width + 15, height + 15);
bool noIntersects = true; bool noIntersects = true;
for(std::size_t i=0; i<m_displayInfo.size(); i++) for (std::size_t i = 0; i < m_displayInfo.size (); i++) {
{ if (rectTest.intersects (m_displayInfo[i].m_rect)) {
if(rectTest.intersects(m_displayInfo[i].m_rect))
{
noIntersects = false; noIntersects = false;
break; break;
} }
@ -249,22 +239,19 @@ GraphDisplay::ElementDisplayInfo GraphDisplay::calculateOnePosition(const Elemen
} }
void GraphDisplay::calculatePositions() void
{ GraphDisplay::calculatePositions ()
while(true)
{ {
while (true) {
std::size_t i = 0; std::size_t i = 0;
for(; i<m_displayInfo.size(); i++) for (; i < m_displayInfo.size (); i++) {
{
std::size_t j = 0; std::size_t j = 0;
for(; j<m_info.size(); j++) for (; j < m_info.size (); j++) {
{
if (m_displayInfo[i].m_id == m_info[j].m_id) if (m_displayInfo[i].m_id == m_info[j].m_id)
break; break;
} }
if(j == m_info.size()) if (j == m_info.size ()) {
{
m_displayInfo.erase (m_displayInfo.begin () + i); m_displayInfo.erase (m_displayInfo.begin () + i);
break; break;
} }
@ -274,13 +261,10 @@ void GraphDisplay::calculatePositions()
break; break;
} }
std::size_t i = 0; std::size_t i = 0;
for(; i<m_info.size(); i++) for (; i < m_info.size (); i++) {
{
std::size_t j = 0; std::size_t j = 0;
for(; j<m_displayInfo.size(); j++) for (; j < m_displayInfo.size (); j++) {
{
if (m_displayInfo[j].m_id == m_info[i].m_id) if (m_displayInfo[j].m_id == m_info[i].m_id)
break; break;
} }
@ -290,12 +274,9 @@ void GraphDisplay::calculatePositions()
} }
std::vector<ElementDisplayInfo> reorderedDisplayInfo (m_info.size ()); std::vector<ElementDisplayInfo> reorderedDisplayInfo (m_info.size ());
for(std::size_t i=0; i<m_info.size(); i++) for (std::size_t i = 0; i < m_info.size (); i++) {
{ for (std::size_t j = 0; j < m_displayInfo.size (); j++) {
for(std::size_t j=0; j<m_displayInfo.size(); j++) if (m_displayInfo[j].m_id == m_info[i].m_id) {
{
if(m_displayInfo[j].m_id == m_info[i].m_id)
{
reorderedDisplayInfo[i] = m_displayInfo[j]; reorderedDisplayInfo[i] = m_displayInfo[j];
break; break;
} }
@ -305,37 +286,31 @@ void GraphDisplay::calculatePositions()
m_displayInfo = reorderedDisplayInfo; m_displayInfo = reorderedDisplayInfo;
} }
void
void GraphDisplay::mousePressEvent(QMouseEvent *event) GraphDisplay::mousePressEvent (QMouseEvent *event)
{ {
std::size_t elementId, padId; std::size_t elementId, padId;
getIdByPosition (event->pos (), elementId, padId); getIdByPosition (event->pos (), elementId, padId);
if (event->buttons () & Qt::RightButton) {
if(event -> buttons() & Qt::RightButton)
{
showContextMenu (event); showContextMenu (event);
} }
else else {
{ if (padId != ((size_t) -1)) {
if(padId != ((size_t)-1))
{
m_moveInfo.m_padId = padId; m_moveInfo.m_padId = padId;
m_moveInfo.m_elementId = elementId; m_moveInfo.m_elementId = elementId;
m_moveInfo.m_position = event->pos (); m_moveInfo.m_position = event->pos ();
m_moveInfo.m_action = MakeConnect; m_moveInfo.m_action = MakeConnect;
m_moveInfo.m_startPosition = event->pos (); m_moveInfo.m_startPosition = event->pos ();
} }
else if(elementId != ((size_t)-1)) else if (elementId != ((size_t) -1)) {
{
m_moveInfo.m_elementId = elementId; m_moveInfo.m_elementId = elementId;
m_moveInfo.m_padId = -1; m_moveInfo.m_padId = -1;
m_moveInfo.m_position = event->pos (); m_moveInfo.m_position = event->pos ();
m_moveInfo.m_action = MoveComponent; m_moveInfo.m_action = MoveComponent;
m_moveInfo.m_startPosition = event->pos (); m_moveInfo.m_startPosition = event->pos ();
} }
else else {
{
m_moveInfo.m_startPosition = event->pos (); m_moveInfo.m_startPosition = event->pos ();
m_moveInfo.m_action = Select; m_moveInfo.m_action = Select;
m_moveInfo.m_position = QPoint (); m_moveInfo.m_position = QPoint ();
@ -346,41 +321,33 @@ void GraphDisplay::mousePressEvent(QMouseEvent *event)
m_displayInfo[i].m_isSelected = false; m_displayInfo[i].m_isSelected = false;
} }
void GraphDisplay::mouseReleaseEvent (QMouseEvent *event) void
{ GraphDisplay::mouseReleaseEvent (QMouseEvent *event)
if(m_moveInfo.m_action == MakeConnect)
{ {
if (m_moveInfo.m_action == MakeConnect) {
std::size_t elementId, padId; std::size_t elementId, padId;
getIdByPosition (event->pos (), elementId, padId); getIdByPosition (event->pos (), elementId, padId);
if(elementId != ((size_t)-1) && padId != ((size_t)-1)) if (elementId != ((size_t) -1) && padId != ((size_t) -1)) {
{
ElementInfo infoSrc, infoDst; ElementInfo infoSrc, infoDst;
const char *srcPad, *dstPad; const char *srcPad, *dstPad;
srcPad = NULL; srcPad = NULL;
dstPad = NULL; dstPad = NULL;
for(std::size_t i=0; i<m_info.size(); i++) for (std::size_t i = 0; i < m_info.size (); i++) {
{ if (m_info[i].m_id == m_moveInfo.m_elementId) {
if(m_info[i].m_id == m_moveInfo.m_elementId)
{
infoSrc = m_info[i]; infoSrc = m_info[i];
for(std::size_t j=0; j<m_info[i].m_pads.size(); j++) for (std::size_t j = 0; j < m_info[i].m_pads.size (); j++) {
{ if (m_info[i].m_pads[j].m_id == m_moveInfo.m_padId) {
if(m_info[i].m_pads[j].m_id == m_moveInfo.m_padId)
{
srcPad = m_info[i].m_pads[j].m_name.c_str (); srcPad = m_info[i].m_pads[j].m_name.c_str ();
break; break;
} }
} }
} }
if(m_info[i].m_id == elementId) if (m_info[i].m_id == elementId) {
{
infoDst = m_info[i]; infoDst = m_info[i];
for(std::size_t j=0; j<m_info[i].m_pads.size(); j++) for (std::size_t j = 0; j < m_info[i].m_pads.size (); j++) {
{ if (m_info[i].m_pads[j].m_id == padId) {
if(m_info[i].m_pads[j].m_id == padId)
{
dstPad = m_info[i].m_pads[j].m_name.c_str (); dstPad = m_info[i].m_pads[j].m_name.c_str ();
break; break;
} }
@ -398,11 +365,11 @@ void GraphDisplay::mouseReleaseEvent (QMouseEvent *event)
assert(srcPad != NULL && dstPad != NULL); assert(srcPad != NULL && dstPad != NULL);
qDebug() << "Connection from " << infoSrc.m_name.c_str() << ":" << srcPad qDebug () << "Connection from " << infoSrc.m_name.c_str () << ":"
<< " to " << infoDst.m_name.c_str() << ":" << dstPad; << srcPad << " to " << infoDst.m_name.c_str () << ":" << dstPad;
if(!m_pGraph -> Connect(infoSrc.m_name.c_str(), srcPad, infoDst.m_name.c_str(), dstPad)) if (!m_pGraph->Connect (infoSrc.m_name.c_str (), srcPad,
{ infoDst.m_name.c_str (), dstPad)) {
QString msg; QString msg;
msg = "Connection "; msg = "Connection ";
msg += QString (infoSrc.m_name.c_str ()) + ":" + srcPad; msg += QString (infoSrc.m_name.c_str ()) + ":" + srcPad;
@ -421,16 +388,15 @@ void GraphDisplay::mouseReleaseEvent (QMouseEvent *event)
} }
} }
} }
else if(m_moveInfo.m_action == Select) else if (m_moveInfo.m_action == Select) {
{ std::size_t width = std::abs (
std::size_t width = std::abs(m_moveInfo.m_position.x() - m_moveInfo.m_startPosition.x()); m_moveInfo.m_position.x () - m_moveInfo.m_startPosition.x ());
std::size_t height = std::abs(m_moveInfo.m_position.y() - m_moveInfo.m_startPosition.y()); std::size_t height = std::abs (
m_moveInfo.m_position.y () - m_moveInfo.m_startPosition.y ());
if(!m_moveInfo.m_position.isNull() && width * height > 5) if (!m_moveInfo.m_position.isNull () && width * height > 5) {
{
QRect selectionRect (m_moveInfo.m_startPosition, m_moveInfo.m_position); QRect selectionRect (m_moveInfo.m_startPosition, m_moveInfo.m_position);
for(std::size_t i=0; i<m_displayInfo.size(); i++) for (std::size_t i = 0; i < m_displayInfo.size (); i++) {
{
if (selectionRect.intersects (m_displayInfo[i].m_rect)) if (selectionRect.intersects (m_displayInfo[i].m_rect))
m_displayInfo[i].m_isSelected = true; m_displayInfo[i].m_isSelected = true;
} }
@ -438,17 +404,13 @@ void GraphDisplay::mouseReleaseEvent (QMouseEvent *event)
repaint (); repaint ();
} }
else if(m_moveInfo.m_action == MoveComponent) else if (m_moveInfo.m_action == MoveComponent) {
{
int dx = event->x () - m_moveInfo.m_startPosition.x (); int dx = event->x () - m_moveInfo.m_startPosition.x ();
int dy = event->y () - m_moveInfo.m_startPosition.y (); int dy = event->y () - m_moveInfo.m_startPosition.y ();
if(dx == dy && dy == 0) if (dx == dy && dy == 0) {
{ for (std::size_t i = 0; i < m_displayInfo.size (); i++) {
for(std::size_t i=0; i<m_displayInfo.size(); i++) if (m_displayInfo[i].m_id == m_moveInfo.m_elementId) {
{
if(m_displayInfo[i].m_id == m_moveInfo.m_elementId)
{
m_displayInfo[i].m_isSelected = true; m_displayInfo[i].m_isSelected = true;
repaint (); repaint ();
break; break;
@ -457,8 +419,7 @@ void GraphDisplay::mouseReleaseEvent (QMouseEvent *event)
} }
} }
exit: exit: m_moveInfo.m_action = None;
m_moveInfo.m_action = None;
m_moveInfo.m_elementId = -1; m_moveInfo.m_elementId = -1;
m_moveInfo.m_padId = -1; m_moveInfo.m_padId = -1;
m_moveInfo.m_startPosition = QPoint (); m_moveInfo.m_startPosition = QPoint ();
@ -466,17 +427,15 @@ exit:
repaint (); repaint ();
} }
void GraphDisplay::mouseMoveEvent(QMouseEvent *event) void
{ GraphDisplay::mouseMoveEvent (QMouseEvent *event)
if(m_moveInfo.m_action == MoveComponent)
{ {
if (m_moveInfo.m_action == MoveComponent) {
int dx = event->x () - m_moveInfo.m_position.x (); int dx = event->x () - m_moveInfo.m_position.x ();
int dy = event->y () - m_moveInfo.m_position.y (); int dy = event->y () - m_moveInfo.m_position.y ();
for(std::size_t i=0; i<m_displayInfo.size(); i++) for (std::size_t i = 0; i < m_displayInfo.size (); i++) {
{ if (m_displayInfo[i].m_id == m_moveInfo.m_elementId) {
if(m_displayInfo[i].m_id == m_moveInfo.m_elementId)
{
QRect newRect = m_displayInfo[i].m_rect; QRect newRect = m_displayInfo[i].m_rect;
newRect.adjust (dx, dy, dx, dy); newRect.adjust (dx, dy, dx, dy);
if (contentsRect ().contains (newRect)) if (contentsRect ().contains (newRect))
@ -486,11 +445,11 @@ void GraphDisplay::mouseMoveEvent(QMouseEvent *event)
} }
} }
if(m_moveInfo.m_action != None) if (m_moveInfo.m_action != None) {
{
m_moveInfo.m_position = event->pos (); m_moveInfo.m_position = event->pos ();
repaint (); repaint ();
} else { }
else {
std::size_t elementId, padId; std::size_t elementId, padId;
getIdByPosition (event->pos (), elementId, padId); getIdByPosition (event->pos (), elementId, padId);
if (padId != ((size_t) -1)) { if (padId != ((size_t) -1)) {
@ -504,7 +463,8 @@ void GraphDisplay::mouseMoveEvent(QMouseEvent *event)
} }
} }
void GraphDisplay::keyPressEvent(QKeyEvent* event) void
GraphDisplay::keyPressEvent (QKeyEvent* event)
{ {
if (event->key () == Qt::Key_Delete) if (event->key () == Qt::Key_Delete)
removeSelected (); removeSelected ();
@ -512,8 +472,8 @@ void GraphDisplay::keyPressEvent(QKeyEvent* event)
return QWidget::keyPressEvent (event); return QWidget::keyPressEvent (event);
} }
void
void GraphDisplay::showContextMenu(QMouseEvent *event) GraphDisplay::showContextMenu (QMouseEvent *event)
{ {
QMenu menu; QMenu menu;
@ -521,11 +481,14 @@ void GraphDisplay::showContextMenu(QMouseEvent *event)
getIdByPosition (event->pos (), elementId, padId); getIdByPosition (event->pos (), elementId, padId);
GstState state; GstState state;
GstStateChangeReturn res = gst_element_get_state (m_pGraph -> m_pGraph, &state, NULL, GST_MSECOND); GstStateChangeReturn res = gst_element_get_state (m_pGraph->m_pGraph, &state,
NULL,
GST_MSECOND);
bool isActive = false; bool isActive = false;
if(res != GST_STATE_CHANGE_SUCCESS || state == GST_STATE_PAUSED || state == GST_STATE_PLAYING) if (res != GST_STATE_CHANGE_SUCCESS || state == GST_STATE_PAUSED
|| state == GST_STATE_PLAYING)
isActive = true; isActive = true;
int selectedCount = 0; int selectedCount = 0;
@ -533,8 +496,7 @@ void GraphDisplay::showContextMenu(QMouseEvent *event)
if (m_displayInfo[i].m_isSelected) if (m_displayInfo[i].m_isSelected)
selectedCount++; selectedCount++;
if(selectedCount > 1) if (selectedCount > 1) {
{
CustomMenuAction *pact = new CustomMenuAction ("Remove selected", &menu); CustomMenuAction *pact = new CustomMenuAction ("Remove selected", &menu);
menu.addAction (pact); menu.addAction (pact);
if (isActive) if (isActive)
@ -547,8 +509,7 @@ void GraphDisplay::showContextMenu(QMouseEvent *event)
menu.addAction (new CustomMenuAction ("Pad properties", &menu)); menu.addAction (new CustomMenuAction ("Pad properties", &menu));
menu.addAction (new CustomMenuAction ("typefind", "ElementName", &menu)); menu.addAction (new CustomMenuAction ("typefind", "ElementName", &menu));
} }
else if(elementId != ((size_t)-1)) else if (elementId != ((size_t) -1)) {
{
menu.addAction (new CustomMenuAction ("Element properties", &menu)); menu.addAction (new CustomMenuAction ("Element properties", &menu));
QAction *pact = new CustomMenuAction ("Remove", &menu); QAction *pact = new CustomMenuAction ("Remove", &menu);
menu.addAction (pact); menu.addAction (pact);
@ -559,22 +520,21 @@ void GraphDisplay::showContextMenu(QMouseEvent *event)
pact = new CustomMenuAction ("Request pad...", &menu); pact = new CustomMenuAction ("Request pad...", &menu);
menu.addAction (pact); menu.addAction (pact);
} }
else else {
{ for (std::size_t i = 0; i < m_info.size (); i++) {
for(std::size_t i=0; i<m_info.size(); i++) for (std::size_t j = 0; j < m_info[i].m_connections.size (); j++) {
{
for(std::size_t j=0; j<m_info[i].m_connections.size(); j++)
{
QPoint point = getPadPosition(m_info[i].m_id, m_info[i].m_pads[j].m_id); QPoint point = getPadPosition (m_info[i].m_id,
m_info[i].m_pads[j].m_id);
double x1, y1; double x1, y1;
x1 = point.x (); x1 = point.x ();
y1 = point.y (); y1 = point.y ();
if(m_info[i].m_connections[j].m_elementId != ((size_t)-1) && m_info[i].m_connections[j].m_padId != ((size_t)-1)) if (m_info[i].m_connections[j].m_elementId != ((size_t) -1)
{ && m_info[i].m_connections[j].m_padId != ((size_t) -1)) {
point = getPadPosition(m_info[i].m_connections[j].m_elementId, m_info[i].m_connections[j].m_padId); point = getPadPosition (m_info[i].m_connections[j].m_elementId,
m_info[i].m_connections[j].m_padId);
double x2, y2; double x2, y2;
x2 = point.x (); x2 = point.x ();
@ -586,7 +546,8 @@ void GraphDisplay::showContextMenu(QMouseEvent *event)
double x0 = event->pos ().x (); double x0 = event->pos ().x ();
double y0 = event->pos ().y (); double y0 = event->pos ().y ();
double distance = std::abs((int)(dy * x0 - dx * y0 + x2 * y1 - y2 * x1)); double distance = std::abs (
(int) (dy * x0 - dx * y0 + x2 * y1 - y2 * x1));
distance = distance / sqrt (dy * dy + dx * dx); distance = distance / sqrt (dy * dy + dx * dx);
if (distance < 5) { if (distance < 5) {
@ -596,7 +557,6 @@ void GraphDisplay::showContextMenu(QMouseEvent *event)
QAction *pact = new CustomMenuAction ("Disconnect", &menu); QAction *pact = new CustomMenuAction ("Disconnect", &menu);
menu.addAction (pact); menu.addAction (pact);
if (isActive) if (isActive)
pact->setDisabled (true); pact->setDisabled (true);
break; break;
@ -608,9 +568,9 @@ void GraphDisplay::showContextMenu(QMouseEvent *event)
} }
} }
if(!menu.isEmpty()) if (!menu.isEmpty ()) {
{ CustomMenuAction *pact = (CustomMenuAction*) menu.exec (
CustomMenuAction *pact = (CustomMenuAction*)menu.exec(event -> globalPos()); event->globalPos ());
if (pact) { if (pact) {
if (pact->getName () == "Remove") if (pact->getName () == "Remove")
removePlugin (elementId); removePlugin (elementId);
@ -634,19 +594,21 @@ void GraphDisplay::showContextMenu(QMouseEvent *event)
} }
} }
void GraphDisplay::removeSelected() void
GraphDisplay::removeSelected ()
{ {
GstState state; GstState state;
GstStateChangeReturn res = gst_element_get_state (m_pGraph -> m_pGraph, &state, NULL, GST_MSECOND); GstStateChangeReturn res = gst_element_get_state (m_pGraph->m_pGraph, &state,
NULL,
GST_MSECOND);
if(res != GST_STATE_CHANGE_SUCCESS || state == GST_STATE_PAUSED || state == GST_STATE_PLAYING) if (res != GST_STATE_CHANGE_SUCCESS || state == GST_STATE_PAUSED
|| state == GST_STATE_PLAYING)
return; return;
while(true) while (true) {
{
std::size_t i = 0; std::size_t i = 0;
for(; i<m_displayInfo.size(); i++) for (; i < m_displayInfo.size (); i++) {
{
if (m_displayInfo[i].m_isSelected) if (m_displayInfo[i].m_isSelected)
break; break;
} }
@ -658,22 +620,26 @@ void GraphDisplay::removeSelected()
} }
} }
void GraphDisplay::removePlugin(std::size_t id) void
GraphDisplay::removePlugin (std::size_t id)
{ {
ElementInfo* element = getElement (id); ElementInfo* element = getElement (id);
if(element) if (element) {
{ if (m_pGraph->RemovePlugin (element->m_name.c_str ())) {
if(m_pGraph -> RemovePlugin(element->m_name.c_str()))
{
std::vector<ElementInfo> info = m_pGraph->GetInfo (); std::vector<ElementInfo> info = m_pGraph->GetInfo ();
update (info); update (info);
} }
else else
QMessageBox::warning(this, "Element removing problem", "Element `" + QString(element->m_name.c_str()) + "` remowing was FAILED"); QMessageBox::warning (
this,
"Element removing problem",
"Element `" + QString (element->m_name.c_str ())
+ "` remowing was FAILED");
} }
} }
void GraphDisplay::connectPlugin(std::size_t elementId, const QString& name) void
GraphDisplay::connectPlugin (std::size_t elementId, const QString& name)
{ {
ElementInfo* element = getElement (elementId); ElementInfo* element = getElement (elementId);
gchar* pluginName = m_pGraph->AddPlugin (name.toStdString ().c_str (), NULL); gchar* pluginName = m_pGraph->AddPlugin (name.toStdString ().c_str (), NULL);
@ -681,28 +647,34 @@ void GraphDisplay::connectPlugin(std::size_t elementId, const QString& name)
g_free (pluginName); g_free (pluginName);
} }
void GraphDisplay::showElementProperties(std::size_t id) void
GraphDisplay::showElementProperties (std::size_t id)
{ {
ElementInfo* element = getElement (id); ElementInfo* element = getElement (id);
if (element) { if (element) {
ElementProperties *pprops = new ElementProperties(m_pGraph,element->m_name.c_str()); ElementProperties *pprops = new ElementProperties (
m_pGraph, element->m_name.c_str ());
pprops->setAttribute (Qt::WA_QuitOnClose, false); pprops->setAttribute (Qt::WA_QuitOnClose, false);
pprops->show (); pprops->show ();
} }
} }
void GraphDisplay::showPadProperties(std::size_t elementId, std::size_t padId) void
GraphDisplay::showPadProperties (std::size_t elementId, std::size_t padId)
{ {
ElementInfo* element = getElement (elementId); ElementInfo* element = getElement (elementId);
PadInfo* pad = getPad (elementId, padId); PadInfo* pad = getPad (elementId, padId);
if (pad) { if (pad) {
PadProperties *pprops = new PadProperties(m_pGraph, element->m_name.c_str(), pad->m_name.c_str()); PadProperties *pprops = new PadProperties (m_pGraph,
element->m_name.c_str (),
pad->m_name.c_str ());
pprops->setAttribute (Qt::WA_QuitOnClose, false); pprops->setAttribute (Qt::WA_QuitOnClose, false);
pprops->show (); pprops->show ();
} }
} }
void GraphDisplay::renderPad(std::size_t elementId, std::size_t padId, bool capsAny) void
GraphDisplay::renderPad (std::size_t elementId, std::size_t padId, bool capsAny)
{ {
ElementInfo* element = getElement (elementId); ElementInfo* element = getElement (elementId);
PadInfo* pad = getPad (elementId, padId); PadInfo* pad = getPad (elementId, padId);
@ -716,8 +688,11 @@ void GraphDisplay::renderPad(std::size_t elementId, std::size_t padId, bool caps
for (l = plugins_list; l != NULL; l = l->next) { for (l = plugins_list; l != NULL; l = l->next) {
Plugin* plugin = (Plugin*) (l->data); Plugin* plugin = (Plugin*) (l->data);
if (m_pGraph->CanConnect(element->m_name.c_str(), pad->m_name.c_str() , plugin->getName().toStdString().c_str(), capsAny)) { if (m_pGraph->CanConnect (element->m_name.c_str (), pad->m_name.c_str (),
gchar* pluginName = m_pGraph->AddPlugin(plugin->getName().toStdString().c_str(), NULL); plugin->getName ().toStdString ().c_str (),
capsAny)) {
gchar* pluginName = m_pGraph->AddPlugin (
plugin->getName ().toStdString ().c_str (), NULL);
m_pGraph->Connect (element->m_name.c_str (), pluginName); m_pGraph->Connect (element->m_name.c_str (), pluginName);
g_free (pluginName); g_free (pluginName);
break; break;
@ -726,27 +701,22 @@ void GraphDisplay::renderPad(std::size_t elementId, std::size_t padId, bool caps
delete pluginList; delete pluginList;
} }
void GraphDisplay::disconnect(size_t elementId, size_t padId) void
GraphDisplay::disconnect (size_t elementId, size_t padId)
{ {
std::string src, dst, srcPad, dstPad; std::string src, dst, srcPad, dstPad;
for(std::size_t i=0; i<m_info.size(); i++) for (std::size_t i = 0; i < m_info.size (); i++) {
{ if (m_info[i].m_id == elementId) {
if(m_info[i].m_id == elementId) for (std::size_t j = 0; j < m_info[i].m_pads.size (); j++) {
{ if (m_info[i].m_pads[j].m_id == padId) {
for(std::size_t j=0; j<m_info[i].m_pads.size(); j++) if (m_info[i].m_pads[j].m_type == PadInfo::Out) {
{
if(m_info[i].m_pads[j].m_id == padId)
{
if(m_info[i].m_pads[j].m_type == PadInfo::Out)
{
src = m_info[i].m_name; src = m_info[i].m_name;
srcPad = m_info[i].m_pads[j].m_name.c_str (); srcPad = m_info[i].m_pads[j].m_name.c_str ();
elementId = m_info[i].m_connections[j].m_elementId; elementId = m_info[i].m_connections[j].m_elementId;
padId = m_info[i].m_connections[j].m_padId; padId = m_info[i].m_connections[j].m_padId;
} }
else else {
{
dst = m_info[i].m_name; dst = m_info[i].m_name;
dstPad = m_info[i].m_pads[j].m_name.c_str (); dstPad = m_info[i].m_pads[j].m_name.c_str ();
elementId = m_info[i].m_connections[j].m_elementId; elementId = m_info[i].m_connections[j].m_elementId;
@ -760,21 +730,15 @@ void GraphDisplay::disconnect(size_t elementId, size_t padId)
} }
} }
for(std::size_t i=0; i<m_info.size(); i++) for (std::size_t i = 0; i < m_info.size (); i++) {
{ if (m_info[i].m_id == elementId) {
if(m_info[i].m_id == elementId) for (std::size_t j = 0; j < m_info[i].m_pads.size (); j++) {
{ if (m_info[i].m_pads[j].m_id == padId) {
for(std::size_t j=0; j<m_info[i].m_pads.size(); j++) if (m_info[i].m_pads[j].m_type == PadInfo::Out) {
{
if(m_info[i].m_pads[j].m_id == padId)
{
if(m_info[i].m_pads[j].m_type == PadInfo::Out)
{
src = m_info[i].m_name; src = m_info[i].m_name;
srcPad = m_info[i].m_pads[j].m_name.c_str (); srcPad = m_info[i].m_pads[j].m_name.c_str ();
} }
else else {
{
dst = m_info[i].m_name; dst = m_info[i].m_name;
dstPad = m_info[i].m_pads[j].m_name.c_str (); dstPad = m_info[i].m_pads[j].m_name.c_str ();
} }
@ -791,15 +755,16 @@ void GraphDisplay::disconnect(size_t elementId, size_t padId)
if (src.empty () || dst.empty () || srcPad.empty () || dstPad.empty ()) if (src.empty () || dst.empty () || srcPad.empty () || dstPad.empty ())
return; return;
m_pGraph->Disconnect (src.c_str (), srcPad.c_str (), dst.c_str (),
m_pGraph->Disconnect(src.c_str(), srcPad.c_str(), dst.c_str(), dstPad.c_str()); dstPad.c_str ());
m_info = m_pGraph->GetInfo (); m_info = m_pGraph->GetInfo ();
updateDisplayInfoIds (); updateDisplayInfoIds ();
repaint (); repaint ();
} }
void GraphDisplay::requestPad(std::size_t elementId) void
GraphDisplay::requestPad (std::size_t elementId)
{ {
QStringList labels; QStringList labels;
labels.push_back ("Template name"); labels.push_back ("Template name");
@ -815,11 +780,12 @@ void GraphDisplay::requestPad(std::size_t elementId)
ElementInfo* elementInfo = getElement (elementId); ElementInfo* elementInfo = getElement (elementId);
GstElement *element = NULL; GstElement *element = NULL;
if (elementInfo) if (elementInfo)
element = gst_bin_get_by_name(GST_BIN(m_pGraph -> m_pGraph),elementInfo->m_name.c_str()); element = gst_bin_get_by_name (GST_BIN (m_pGraph->m_pGraph),
elementInfo->m_name.c_str ());
if(!element) if (!element) {
{ QMessageBox::warning (this, "Request pad failed",
QMessageBox::warning(this, "Request pad failed", "Request pad list obtaining was failed"); "Request pad list obtaining was failed");
return; return;
} }
@ -829,15 +795,14 @@ void GraphDisplay::requestPad(std::size_t elementId)
GList *lst = gst_element_class_get_pad_template_list (klass); GList *lst = gst_element_class_get_pad_template_list (klass);
std::size_t k = 0; std::size_t k = 0;
while (lst != NULL) while (lst != NULL) {
{
GstPadTemplate *templ; GstPadTemplate *templ;
templ = (GstPadTemplate *) lst->data; templ = (GstPadTemplate *) lst->data;
if(GST_PAD_TEMPLATE_PRESENCE(templ) == GST_PAD_REQUEST) if (GST_PAD_TEMPLATE_PRESENCE (templ) == GST_PAD_REQUEST) {
{
ptwgt->setRowCount (k + 1); ptwgt->setRowCount (k + 1);
ptwgt -> setItem(k, 0, new QTableWidgetItem(GST_PAD_TEMPLATE_NAME_TEMPLATE(templ))); ptwgt->setItem (
k, 0, new QTableWidgetItem (GST_PAD_TEMPLATE_NAME_TEMPLATE (templ)));
GstCaps *caps = gst_pad_template_get_caps (templ); GstCaps *caps = gst_pad_template_get_caps (templ);
gchar *capsStr = gst_caps_to_string (caps); gchar *capsStr = gst_caps_to_string (caps);
@ -850,8 +815,7 @@ void GraphDisplay::requestPad(std::size_t elementId)
const char *directionUnknown = "UNKNOWN"; const char *directionUnknown = "UNKNOWN";
QString direction; QString direction;
switch(GST_PAD_TEMPLATE_DIRECTION(templ)) switch (GST_PAD_TEMPLATE_DIRECTION (templ)) {
{
case GST_PAD_UNKNOWN: case GST_PAD_UNKNOWN:
direction = directionUnknown; direction = directionUnknown;
break; break;
@ -881,7 +845,8 @@ void GraphDisplay::requestPad(std::size_t elementId)
ptwgt->show (); ptwgt->show ();
} }
void GraphDisplay::addRequestPad(int row, int collumn) void
GraphDisplay::addRequestPad (int row, int collumn)
{ {
QTableWidget *ptwgt = dynamic_cast<QTableWidget *> (QObject::sender ()); QTableWidget *ptwgt = dynamic_cast<QTableWidget *> (QObject::sender ());
@ -889,7 +854,8 @@ void GraphDisplay::addRequestPad(int row, int collumn)
GstElement *element = (GstElement *) v; GstElement *element = (GstElement *) v;
GstElementClass *klass = GST_ELEMENT_GET_CLASS (element); GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
GstPadTemplate *templ = gst_element_class_get_pad_template(klass, ptwgt -> itemAt(row, 0) -> text().toStdString().c_str()); GstPadTemplate *templ = gst_element_class_get_pad_template (
klass, ptwgt->itemAt (row, 0)->text ().toStdString ().c_str ());
gst_element_request_pad (element, templ, NULL, NULL); gst_element_request_pad (element, templ, NULL, NULL);
@ -901,27 +867,25 @@ void GraphDisplay::addRequestPad(int row, int collumn)
} }
void GraphDisplay::getIdByPosition(const QPoint &pos, std::size_t &elementId, std::size_t &padId) void
GraphDisplay::getIdByPosition (const QPoint &pos, std::size_t &elementId,
std::size_t &padId)
{ {
std::size_t i = 0; std::size_t i = 0;
elementId = padId = -1; elementId = padId = -1;
for(; i<m_displayInfo.size(); i++) for (; i < m_displayInfo.size (); i++) {
{
if (elementId != ((size_t) -1)) if (elementId != ((size_t) -1))
break; break;
QRect rect( QRect rect (m_displayInfo[i].m_rect.x () - 8,
m_displayInfo[i].m_rect.x() - 8,
m_displayInfo[i].m_rect.y () - 6, m_displayInfo[i].m_rect.y () - 6,
m_displayInfo[i].m_rect.width () + 16, m_displayInfo[i].m_rect.width () + 16,
m_displayInfo[i].m_rect.height() + 12 m_displayInfo[i].m_rect.height () + 12);
); if (rect.contains (pos)) {
if(rect.contains(pos))
{
std::size_t j = 0; std::size_t j = 0;
for(; j<m_info[i].m_pads.size(); j++) for (; j < m_info[i].m_pads.size (); j++) {
{ QPoint point = getPadPosition (m_displayInfo[i].m_id,
QPoint point = getPadPosition(m_displayInfo[i].m_id, m_info[i].m_pads[j].m_id); m_info[i].m_pads[j].m_id);
int xPos, yPos; int xPos, yPos;
xPos = point.x (); xPos = point.x ();
@ -931,16 +895,14 @@ void GraphDisplay::getIdByPosition(const QPoint &pos, std::size_t &elementId, st
yPos -= PAD_SIZE_ACTION / 2; yPos -= PAD_SIZE_ACTION / 2;
QRect rect (xPos, yPos, PAD_SIZE_ACTION, PAD_SIZE_ACTION); QRect rect (xPos, yPos, PAD_SIZE_ACTION, PAD_SIZE_ACTION);
if(rect.contains(pos)) if (rect.contains (pos)) {
{
padId = m_info[i].m_pads[j].m_id; padId = m_info[i].m_pads[j].m_id;
elementId = m_displayInfo[i].m_id; elementId = m_displayInfo[i].m_id;
break; break;
} }
} }
if(j == m_info[i].m_pads.size()) if (j == m_info[i].m_pads.size ()) {
{
if (m_displayInfo[i].m_rect.contains (pos)) if (m_displayInfo[i].m_rect.contains (pos))
elementId = m_displayInfo[i].m_id; elementId = m_displayInfo[i].m_id;
} }
@ -948,20 +910,18 @@ void GraphDisplay::getIdByPosition(const QPoint &pos, std::size_t &elementId, st
} }
} }
QPoint GraphDisplay::getPadPosition(std::size_t elementId, std::size_t padId) QPoint
GraphDisplay::getPadPosition (std::size_t elementId, std::size_t padId)
{ {
QPoint res; QPoint res;
if (elementId == ((size_t) -1) || padId == ((size_t) -1)) if (elementId == ((size_t) -1) || padId == ((size_t) -1))
return res; return res;
for(std::size_t i=0; i<m_displayInfo.size(); i++) for (std::size_t i = 0; i < m_displayInfo.size (); i++) {
{ if (m_displayInfo[i].m_id == elementId) {
if(m_displayInfo[i].m_id == elementId)
{
int numInPads, numOutPads; int numInPads, numOutPads;
numInPads = numOutPads = 0; numInPads = numOutPads = 0;
for(std::size_t j=0; j<m_info[i].m_pads.size(); j++) for (std::size_t j = 0; j < m_info[i].m_pads.size (); j++) {
{
if (m_info[i].m_pads[j].m_type == PadInfo::Out) if (m_info[i].m_pads[j].m_type == PadInfo::Out)
numOutPads++; numOutPads++;
else if (m_info[i].m_pads[j].m_type == PadInfo::In) else if (m_info[i].m_pads[j].m_type == PadInfo::In)
@ -975,26 +935,22 @@ QPoint GraphDisplay::getPadPosition(std::size_t elementId, std::size_t padId)
inPos = inDelta; inPos = inDelta;
outPos = outDelta; outPos = outDelta;
for(std::size_t j=0; j<m_info[i].m_pads.size(); j++) for (std::size_t j = 0; j < m_info[i].m_pads.size (); j++) {
{
int xPos, yPos; int xPos, yPos;
yPos = m_displayInfo[i].m_rect.topRight ().y (); yPos = m_displayInfo[i].m_rect.topRight ().y ();
if(m_info[i].m_pads[j].m_type == PadInfo::Out) if (m_info[i].m_pads[j].m_type == PadInfo::Out) {
{
xPos = m_displayInfo[i].m_rect.topRight ().x (); xPos = m_displayInfo[i].m_rect.topRight ().x ();
yPos += outPos; yPos += outPos;
outPos += outDelta; outPos += outDelta;
} }
else if(m_info[i].m_pads[j].m_type == PadInfo::In) else if (m_info[i].m_pads[j].m_type == PadInfo::In) {
{
xPos = m_displayInfo[i].m_rect.topLeft ().x (); xPos = m_displayInfo[i].m_rect.topLeft ().x ();
yPos += inPos; yPos += inPos;
inPos += inDelta; inPos += inDelta;
} }
if(m_info[i].m_pads[j].m_id == padId) if (m_info[i].m_pads[j].m_id == padId) {
{
res = QPoint (xPos, yPos); res = QPoint (xPos, yPos);
break; break;
} }

View file

@ -7,13 +7,9 @@
#include <QSharedPointer> #include <QSharedPointer>
#include <QPoint> #include <QPoint>
#include "GraphManager.h" #include "GraphManager.h"
#include <vector> #include <vector>
class GraphDisplay: public QWidget class GraphDisplay: public QWidget
{ {
Q_OBJECT Q_OBJECT
@ -28,7 +24,6 @@ public:
void keyPressEvent(QKeyEvent* event); void keyPressEvent(QKeyEvent* event);
QSharedPointer<GraphManager> m_pGraph; QSharedPointer<GraphManager> m_pGraph;
private slots: private slots:
@ -57,7 +52,6 @@ private:
QPoint m_startPosition; QPoint m_startPosition;
}; };
struct ElementDisplayInfo struct ElementDisplayInfo
{ {
QRect m_rect; QRect m_rect;
@ -90,5 +84,4 @@ private:
MoveInfo m_moveInfo; MoveInfo m_moveInfo;
}; };
#endif #endif

View file

@ -10,24 +10,27 @@
#include "CustomSettings.h" #include "CustomSettings.h"
#define MAX_STR_CAPS_SIZE 150 #define MAX_STR_CAPS_SIZE 150
gchar* get_str_caps_limited(gchar* str) gchar*
get_str_caps_limited (gchar* str)
{ {
gchar* result; gchar* result;
if (strlen (str) > MAX_STR_CAPS_SIZE) { if (strlen (str) > MAX_STR_CAPS_SIZE) {
result = g_strndup (str, MAX_STR_CAPS_SIZE); result = g_strndup (str, MAX_STR_CAPS_SIZE);
for (int i = strlen (result) - 1; i > strlen (result) - 4; i--) for (int i = strlen (result) - 1; i > strlen (result) - 4; i--)
result[i] = '.'; result[i] = '.';
} else }
else
result = g_strdup (str); result = g_strdup (str);
return result; return result;
} }
static void static void
typefind_have_type_callback (GstElement * typefind, typefind_have_type_callback (GstElement * typefind, guint probability,
guint probability, GstCaps * caps, GraphManager * thiz) GstCaps * caps, GraphManager * thiz)
{ {
gchar *caps_description = gst_caps_to_string (caps); gchar *caps_description = gst_caps_to_string (caps);
qDebug() << "Found caps " << caps_description << " with probability " << probability; qDebug () << "Found caps " << caps_description << " with probability "
<< probability;
g_free (caps_description); g_free (caps_description);
thiz->Pause (); thiz->Pause ();
} }
@ -43,24 +46,27 @@ GraphManager::~GraphManager()
delete m_pluginsList; delete m_pluginsList;
} }
QString GraphManager::getPadCaps(ElementInfo* elementInfo, PadInfo* padInfo, ePadCapsSubset subset, bool afTruncated) QString
GraphManager::getPadCaps (ElementInfo* elementInfo, PadInfo* padInfo,
ePadCapsSubset subset, bool afTruncated)
{ {
QString padCaps = ""; QString padCaps = "";
if (!elementInfo || !padInfo) if (!elementInfo || !padInfo)
return padCaps; return padCaps;
GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraph), elementInfo->m_name.c_str()); GstElement *element = gst_bin_get_by_name (GST_BIN (m_pGraph),
elementInfo->m_name.c_str ());
if (!element) if (!element)
return padCaps; return padCaps;
GstPad *pad = gst_element_get_static_pad(GST_ELEMENT(element), padInfo->m_name.c_str()); GstPad *pad = gst_element_get_static_pad (GST_ELEMENT (element),
padInfo->m_name.c_str ());
if (!pad) { if (!pad) {
gst_object_unref (element); gst_object_unref (element);
return padCaps; return padCaps;
} }
GstCaps *caps; GstCaps *caps;
switch(subset) switch (subset) {
{
case PAD_CAPS_ALLOWED: case PAD_CAPS_ALLOWED:
caps = gst_pad_get_allowed_caps (pad); caps = gst_pad_get_allowed_caps (pad);
break; break;
@ -91,7 +97,8 @@ QString GraphManager::getPadCaps(ElementInfo* elementInfo, PadInfo* padInfo, ePa
g_free (str); g_free (str);
padCaps = str_limited; padCaps = str_limited;
g_free (str_limited); g_free (str_limited);
} else { }
else {
padCaps = str; padCaps = str;
g_free (str); g_free (str);
} }
@ -103,43 +110,40 @@ QString GraphManager::getPadCaps(ElementInfo* elementInfo, PadInfo* padInfo, ePa
return padCaps; return padCaps;
} }
gchar* GraphManager::AddPlugin(const char *plugin, const char *name) gchar*
GraphManager::AddPlugin (const char *plugin, const char *name)
{ {
GstElement *pel = gst_element_factory_make (plugin, name); GstElement *pel = gst_element_factory_make (plugin, name);
if (!pel) if (!pel)
return NULL; return NULL;
if(GST_IS_URI_HANDLER(pel)) if (GST_IS_URI_HANDLER (pel)) {
{
static const gchar * const *protocols; static const gchar * const *protocols;
protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (pel)); protocols = gst_uri_handler_get_protocols (GST_URI_HANDLER (pel));
bool isFile = false; bool isFile = false;
for(std::size_t i=0; protocols[i] != NULL; i++) for (std::size_t i = 0; protocols[i] != NULL; i++) {
{ if (strcmp ("file", protocols[i]) == 0) {
if(strcmp("file", protocols[i]) == 0)
{
isFile = true; isFile = true;
break; break;
} }
} }
if(isFile) if (isFile) {
{
QString path; QString path;
QString dir = CustomSettings::lastIODirectory (); QString dir = CustomSettings::lastIODirectory ();
if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (pel)) == GST_URI_SRC) if (gst_uri_handler_get_uri_type (GST_URI_HANDLER (pel)) == GST_URI_SRC)
path = QFileDialog::getOpenFileName(NULL, "Open Media Source File...", dir); path = QFileDialog::getOpenFileName (NULL, "Open Media Source File...",
dir);
else else
path = QFileDialog::getSaveFileName (NULL, "Open Sink File...", dir); path = QFileDialog::getSaveFileName (NULL, "Open Sink File...", dir);
if(!path.isEmpty()) if (!path.isEmpty ()) {
{ gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (),
gchar *uri = gst_filename_to_uri(path.toStdString().c_str(), NULL); NULL);
if(uri) if (uri) {
{
qDebug () << "Set uri: " << uri; qDebug () << "Set uri: " << uri;
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri, NULL); gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri, NULL);
@ -153,17 +157,16 @@ gchar* GraphManager::AddPlugin(const char *plugin, const char *name)
} }
} }
} }
else else {
{
QString uri = QInputDialog::getText (NULL, "Uri...", "Uri:"); QString uri = QInputDialog::getText (NULL, "Uri...", "Uri:");
if(!uri.isEmpty()) if (!uri.isEmpty ()) {
{
qDebug () << "Set uri: " << uri; qDebug () << "Set uri: " << uri;
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri.toStdString().c_str(), NULL); gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri.toStdString().c_str(), NULL);
#else #else
gst_uri_handler_set_uri(GST_URI_HANDLER(pel), uri.toStdString().c_str()); gst_uri_handler_set_uri (GST_URI_HANDLER (pel),
uri.toStdString ().c_str ());
#endif #endif
} }
} }
@ -180,8 +183,8 @@ gchar* GraphManager::AddPlugin(const char *plugin, const char *name)
return gst_element_get_name (pel); return gst_element_get_name (pel);
} }
bool
bool GraphManager::RemovePlugin(const char *name) GraphManager::RemovePlugin (const char *name)
{ {
GstElement *element = gst_bin_get_by_name (GST_BIN (m_pGraph), name); GstElement *element = gst_bin_get_by_name (GST_BIN (m_pGraph), name);
@ -194,8 +197,8 @@ bool GraphManager::RemovePlugin(const char *name)
return res; return res;
} }
bool
bool GraphManager::OpenUri(const char *uri, const char *name) GraphManager::OpenUri (const char *uri, const char *name)
{ {
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
GstElement *element = gst_element_make_from_uri(GST_URI_SRC, uri, name, NULL); GstElement *element = gst_element_make_from_uri(GST_URI_SRC, uri, name, NULL);
@ -212,7 +215,8 @@ bool GraphManager::OpenUri(const char *uri, const char *name)
return res; return res;
} }
bool GraphManager::Connect(const char *srcElement, const char *srcPad, bool
GraphManager::Connect (const char *srcElement, const char *srcPad,
const char *dstElement, const char *dstPad) const char *dstElement, const char *dstPad)
{ {
GstElement *src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcElement); GstElement *src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcElement);
@ -220,7 +224,8 @@ bool GraphManager::Connect(const char *srcElement, const char *srcPad,
bool res = gst_element_link_pads (src, srcPad, dst, dstPad); bool res = gst_element_link_pads (src, srcPad, dst, dstPad);
gboolean seekRes = gst_element_seek_simple(m_pGraph, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, 0); gboolean seekRes = gst_element_seek_simple (m_pGraph, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH, 0);
gst_object_unref (src); gst_object_unref (src);
gst_object_unref (dst); gst_object_unref (dst);
@ -228,20 +233,21 @@ bool GraphManager::Connect(const char *srcElement, const char *srcPad,
return res; return res;
} }
bool GraphManager::Connect(const char *srcElement, const char *dstElement) bool
GraphManager::Connect (const char *srcElement, const char *dstElement)
{ {
GstElement *src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcElement); GstElement *src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcElement);
GstElement *dst = gst_bin_get_by_name (GST_BIN (m_pGraph), dstElement); GstElement *dst = gst_bin_get_by_name (GST_BIN (m_pGraph), dstElement);
bool res = gst_element_link (src, dst); bool res = gst_element_link (src, dst);
gboolean seekRes = gst_element_seek_simple(m_pGraph, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, 0); gboolean seekRes = gst_element_seek_simple (m_pGraph, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH, 0);
/* add a callback to handle have-type signal */ /* add a callback to handle have-type signal */
if (g_str_has_prefix (dstElement, "typefindelement")) { if (g_str_has_prefix (dstElement, "typefindelement")) {
g_signal_connect (dst, "have-type", g_signal_connect (dst, "have-type",
G_CALLBACK (typefind_have_type_callback), G_CALLBACK (typefind_have_type_callback), this);
this);
Play (); Play ();
} }
@ -251,13 +257,13 @@ bool GraphManager::Connect(const char *srcElement, const char *dstElement)
return res; return res;
} }
bool GraphManager::Disconnect(const char *srcElement, const char *srcPad, bool
GraphManager::Disconnect (const char *srcElement, const char *srcPad,
const char *dstElement, const char *dstPad) const char *dstElement, const char *dstPad)
{ {
GstElement *src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcElement); GstElement *src = gst_bin_get_by_name (GST_BIN (m_pGraph), srcElement);
GstElement *dst = gst_bin_get_by_name (GST_BIN (m_pGraph), dstElement); GstElement *dst = gst_bin_get_by_name (GST_BIN (m_pGraph), dstElement);
gst_element_unlink_pads (src, srcPad, dst, dstPad); gst_element_unlink_pads (src, srcPad, dst, dstPad);
gst_object_unref (src); gst_object_unref (src);
@ -266,7 +272,8 @@ bool GraphManager::Disconnect(const char *srcElement, const char *srcPad,
return true; return true;
} }
std::vector <ElementInfo> GraphManager::GetInfo() std::vector<ElementInfo>
GraphManager::GetInfo ()
{ {
std::vector<ElementInfo> res; std::vector<ElementInfo> res;
@ -275,20 +282,18 @@ std::vector <ElementInfo> GraphManager::GetInfo()
GstElement* element = NULL; GstElement* element = NULL;
bool done = false; bool done = false;
size_t id = 0; size_t id = 0;
while (!done) while (!done) {
{
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
GValue value = { 0 }; GValue value =
{ 0};
switch (gst_iterator_next (iter, &value)) switch (gst_iterator_next (iter, &value))
{ {
case GST_ITERATOR_OK: case GST_ITERATOR_OK:
{ {
element = GST_ELEMENT(g_value_get_object(&value)); element = GST_ELEMENT(g_value_get_object(&value));
#else #else
switch (gst_iterator_next (iter, (gpointer *)&element)) switch (gst_iterator_next (iter, (gpointer *) &element)) {
{ case GST_ITERATOR_OK: {
case GST_ITERATOR_OK:
{
#endif #endif
ElementInfo elementInfo; ElementInfo elementInfo;
elementInfo.m_id = id; elementInfo.m_id = id;
@ -298,30 +303,27 @@ std::vector <ElementInfo> GraphManager::GetInfo()
elementInfo.m_name = name; elementInfo.m_name = name;
g_free (name); g_free (name);
GstElementFactory *pfactory = GstElementFactory *pfactory = gst_element_get_factory (element);
gst_element_get_factory(element);
elementInfo.m_pluginName = elementInfo.m_pluginName = gst_plugin_feature_get_name (
gst_plugin_feature_get_name(GST_PLUGIN_FEATURE(pfactory)); GST_PLUGIN_FEATURE (pfactory));
GstIterator *padItr = gst_element_iterate_pads (element); GstIterator *padItr = gst_element_iterate_pads (element);
bool padDone = FALSE; bool padDone = FALSE;
std::size_t padId = 0; std::size_t padId = 0;
GstPad *pad; GstPad *pad;
while (!padDone) while (!padDone) {
{
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
GValue padVal = { 0 }; GValue padVal =
{ 0};
switch (gst_iterator_next (padItr, &padVal)) switch (gst_iterator_next (padItr, &padVal))
{ {
case GST_ITERATOR_OK: case GST_ITERATOR_OK:
{ {
pad = GST_PAD(g_value_get_object(&padVal)); pad = GST_PAD(g_value_get_object(&padVal));
#else #else
switch (gst_iterator_next (padItr, (gpointer *)&pad)) switch (gst_iterator_next (padItr, (gpointer *) &pad)) {
{ case GST_ITERATOR_OK: {
case GST_ITERATOR_OK:
{
#endif #endif
PadInfo padInfo; PadInfo padInfo;
padInfo.m_id = padId; padInfo.m_id = padId;
@ -360,8 +362,7 @@ std::vector <ElementInfo> GraphManager::GetInfo()
} }
case GST_ITERATOR_DONE: case GST_ITERATOR_DONE:
case GST_ITERATOR_RESYNC: case GST_ITERATOR_RESYNC:
case GST_ITERATOR_ERROR: case GST_ITERATOR_ERROR: {
{
done = true; done = true;
break; break;
} }
@ -370,35 +371,30 @@ std::vector <ElementInfo> GraphManager::GetInfo()
gst_iterator_free (iter); gst_iterator_free (iter);
for(std::size_t i=0; i<res.size(); i++) for (std::size_t i = 0; i < res.size (); i++) {
{
res[i].m_connections.resize (res[i].m_pads.size ()); res[i].m_connections.resize (res[i].m_pads.size ());
GstElement *element = gst_bin_get_by_name (GST_BIN(m_pGraph), res[i].m_name.c_str()); GstElement *element = gst_bin_get_by_name (GST_BIN (m_pGraph),
res[i].m_name.c_str ());
for(std::size_t j=0; j<res[i].m_pads.size(); j++) for (std::size_t j = 0; j < res[i].m_pads.size (); j++) {
{
res[i].m_connections[j].m_elementId = -1; res[i].m_connections[j].m_elementId = -1;
res[i].m_connections[j].m_padId = -1; res[i].m_connections[j].m_padId = -1;
GstPad *pad = gst_element_get_static_pad (element, res[i].m_pads[j].m_name.c_str()); GstPad *pad = gst_element_get_static_pad (
element, res[i].m_pads[j].m_name.c_str ());
GstPad *peerPad = gst_pad_get_peer (pad); GstPad *peerPad = gst_pad_get_peer (pad);
if(peerPad) if (peerPad) {
{
GstElement *peerElement = GST_ELEMENT (gst_pad_get_parent (peerPad)); GstElement *peerElement = GST_ELEMENT (gst_pad_get_parent (peerPad));
gchar *peerName = gst_element_get_name (peerElement); gchar *peerName = gst_element_get_name (peerElement);
gchar *peerPadName = gst_pad_get_name (peerPad); gchar *peerPadName = gst_pad_get_name (peerPad);
for(std::size_t k=0; k<res.size(); k++) for (std::size_t k = 0; k < res.size (); k++) {
{ if (res[k].m_name == peerName) {
if(res[k].m_name == peerName) for (std::size_t l = 0; l < res[k].m_pads.size (); l++) {
{ if (res[k].m_pads[l].m_name == peerPadName) {
for(std::size_t l=0; l<res[k].m_pads.size(); l++)
{
if(res[k].m_pads[l].m_name == peerPadName)
{
res[i].m_connections[j].m_elementId = res[k].m_id; res[i].m_connections[j].m_elementId = res[k].m_id;
res[i].m_connections[j].m_padId = res[k].m_pads[l].m_id; res[i].m_connections[j].m_padId = res[k].m_pads[l].m_id;
break; break;
@ -423,8 +419,8 @@ std::vector <ElementInfo> GraphManager::GetInfo()
return res; return res;
} }
bool
bool GraphManager::Play() GraphManager::Play ()
{ {
GstStateChangeReturn res; GstStateChangeReturn res;
gst_element_set_state (m_pGraph, GST_STATE_PLAYING); gst_element_set_state (m_pGraph, GST_STATE_PLAYING);
@ -432,8 +428,7 @@ bool GraphManager::Play()
GstState state; GstState state;
res = gst_element_get_state (m_pGraph, &state, NULL, GST_SECOND); res = gst_element_get_state (m_pGraph, &state, NULL, GST_SECOND);
if(res != GST_STATE_CHANGE_SUCCESS) if (res != GST_STATE_CHANGE_SUCCESS) {
{
gst_element_abort_state (m_pGraph); gst_element_abort_state (m_pGraph);
qDebug () << "state changing to Play was FAILED"; qDebug () << "state changing to Play was FAILED";
} }
@ -441,16 +436,15 @@ bool GraphManager::Play()
return state == GST_STATE_PLAYING; return state == GST_STATE_PLAYING;
} }
bool
bool GraphManager::Pause() GraphManager::Pause ()
{ {
GstStateChangeReturn res; GstStateChangeReturn res;
GstState state; GstState state;
gst_element_set_state (m_pGraph, GST_STATE_PAUSED); gst_element_set_state (m_pGraph, GST_STATE_PAUSED);
res = gst_element_get_state (m_pGraph, &state, NULL, GST_SECOND); res = gst_element_get_state (m_pGraph, &state, NULL, GST_SECOND);
if(res != GST_STATE_CHANGE_SUCCESS) if (res != GST_STATE_CHANGE_SUCCESS) {
{
gst_element_abort_state (m_pGraph); gst_element_abort_state (m_pGraph);
qDebug () << "state changing to Pause was FAILED"; qDebug () << "state changing to Pause was FAILED";
} }
@ -458,13 +452,15 @@ bool GraphManager::Pause()
return state == GST_STATE_PAUSED; return state == GST_STATE_PAUSED;
} }
bool GraphManager::Stop() bool
GraphManager::Stop ()
{ {
GstStateChangeReturn res = gst_element_set_state (m_pGraph, GST_STATE_READY); GstStateChangeReturn res = gst_element_set_state (m_pGraph, GST_STATE_READY);
return res == GST_STATE_CHANGE_SUCCESS; return res == GST_STATE_CHANGE_SUCCESS;
} }
double GraphManager::GetPosition() double
GraphManager::GetPosition ()
{ {
gint64 current, duration; gint64 current, duration;
GstFormat fmt = GST_FORMAT_TIME; GstFormat fmt = GST_FORMAT_TIME;
@ -490,8 +486,8 @@ double GraphManager::GetPosition()
return (double) current / duration; return (double) current / duration;
} }
bool
bool GraphManager::SetPosition(double pos) GraphManager::SetPosition (double pos)
{ {
GstQuery *query = gst_query_new_seeking (GST_FORMAT_TIME); GstQuery *query = gst_query_new_seeking (GST_FORMAT_TIME);
GstFormat fmt = GST_FORMAT_TIME; GstFormat fmt = GST_FORMAT_TIME;
@ -522,12 +518,16 @@ bool GraphManager::SetPosition(double pos)
if (duration < 0) if (duration < 0)
return 0; return 0;
gboolean seekRes = gst_element_seek_simple(m_pGraph, GST_FORMAT_TIME, GST_SEEK_FLAG_FLUSH, duration * pos); gboolean seekRes = gst_element_seek_simple (m_pGraph, GST_FORMAT_TIME,
GST_SEEK_FLAG_FLUSH,
duration * pos);
return seekRes; return seekRes;
} }
bool GraphManager::CanConnect(const char *srcName, const char *srcPadName, const char *destName, bool noANY) bool
GraphManager::CanConnect (const char *srcName, const char *srcPadName,
const char *destName, bool noANY)
{ {
bool ret = false; bool ret = false;
bool added = false; bool added = false;
@ -577,7 +577,8 @@ bool GraphManager::CanConnect(const char *srcName, const char *srcPadName, const
if (!gst_element_factory_can_sink_all_caps (destFactory, srcCaps)) { if (!gst_element_factory_can_sink_all_caps (destFactory, srcCaps)) {
gchar* caps_string = gst_caps_to_string (srcCaps); gchar* caps_string = gst_caps_to_string (srcCaps);
qDebug() << "The dest element " << destName << " can not sink this caps: " << caps_string; qDebug () << "The dest element " << destName << " can not sink this caps: "
<< caps_string;
g_free (caps_string); g_free (caps_string);
goto done; goto done;
} }
@ -590,12 +591,12 @@ bool GraphManager::CanConnect(const char *srcName, const char *srcPadName, const
ret = gst_element_link (src, dest); ret = gst_element_link (src, dest);
if (ret) { if (ret) {
qDebug() << "Can link elements src " << GST_OBJECT_NAME(src) << " with dest " << GST_OBJECT_NAME(dest); qDebug () << "Can link elements src " << GST_OBJECT_NAME (src)
<< " with dest " << GST_OBJECT_NAME (dest);
gst_element_unlink (src, dest); gst_element_unlink (src, dest);
} }
done: done: if (added) {
if (added) {
gst_bin_remove (GST_BIN (m_pGraph), dest); gst_bin_remove (GST_BIN (m_pGraph), dest);
dest = NULL; dest = NULL;
} }

View file

@ -81,6 +81,7 @@ struct ElementInfo
class GraphManager class GraphManager
{ {
public: public:
GraphManager(); GraphManager();
~GraphManager(); ~GraphManager();
@ -111,8 +112,6 @@ public:
GstElement *m_pGraph; GstElement *m_pGraph;
PluginsList *m_pluginsList; PluginsList *m_pluginsList;
}; };
#endif #endif

View file

@ -33,9 +33,9 @@
#include <gst/gst.h> #include <gst/gst.h>
MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags): MainWindow::MainWindow (QWidget *parent, Qt::WindowFlags flags)
QMainWindow(parent, flags) : QMainWindow (parent, flags),
,m_pGraph(new GraphManager) m_pGraph (new GraphManager)
{ {
QToolBar *ptb = addToolBar ("Menu"); QToolBar *ptb = addToolBar ("Menu");
@ -43,7 +43,6 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags):
pactAdd->setShortcut (QKeySequence ("Ctrl+F")); pactAdd->setShortcut (QKeySequence ("Ctrl+F"));
connect (pactAdd, SIGNAL (triggered ()), SLOT (AddPlugin ())); connect (pactAdd, SIGNAL (triggered ()), SLOT (AddPlugin ()));
QAction *pactOpenFile = ptb->addAction ("Open Media File..."); QAction *pactOpenFile = ptb->addAction ("Open Media File...");
connect (pactOpenFile, SIGNAL (triggered ()), SLOT (OpenMediaFile ())); connect (pactOpenFile, SIGNAL (triggered ()), SLOT (OpenMediaFile ()));
@ -120,22 +119,26 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags):
QMenu *pmenu = menuBar ()->addMenu ("&File"); QMenu *pmenu = menuBar ()->addMenu ("&File");
QAction *pactOpen = pmenu -> addAction ("Open...", this, SLOT(Open()), QKeySequence::Open); QAction *pactOpen = pmenu->addAction ("Open...", this, SLOT (Open ()),
QKeySequence::Open);
addAction (pactOpen); addAction (pactOpen);
QAction *pactOpenMediaFile = pmenu -> addAction ("Open Media File...", this, SLOT(OpenMediaFile()), QKeySequence::Open); QAction *pactOpenMediaFile = pmenu->addAction ("Open Media File...", this,
SLOT (OpenMediaFile ()),
QKeySequence::Open);
addAction (pactOpenMediaFile); addAction (pactOpenMediaFile);
QAction *pactSave = pmenu -> addAction ("Save", this, SLOT(Save()), QKeySequence::Save); QAction *pactSave = pmenu->addAction ("Save", this, SLOT (Save ()),
QKeySequence::Save);
addAction (pactSave); addAction (pactSave);
QAction *pactSaveAs = pmenu -> addAction ("Save As...", this, SLOT(SaveAs()), QKeySequence::SaveAs); QAction *pactSaveAs = pmenu->addAction ("Save As...", this, SLOT (SaveAs ()),
QKeySequence::SaveAs);
addAction (pactSaveAs); addAction (pactSaveAs);
pmenu->addSeparator (); pmenu->addSeparator ();
pmenu->addAction ("Exit", this, SLOT (close ())); pmenu->addAction ("Exit", this, SLOT (close ()));
pmenu = menuBar ()->addMenu ("&Graph"); pmenu = menuBar ()->addMenu ("&Graph");
pmenu->addAction (pactAdd); pmenu->addAction (pactAdd);
@ -149,12 +152,10 @@ MainWindow::MainWindow(QWidget *parent, Qt::WindowFlags flags):
pmenu->addSeparator (); pmenu->addSeparator ();
pmenu->addAction (pactClear); pmenu->addAction (pactClear);
pmenu = menuBar ()->addMenu ("&Help"); pmenu = menuBar ()->addMenu ("&Help");
pmenu->addAction ("About pipeviz...", this, SLOT (About ())); pmenu->addAction ("About pipeviz...", this, SLOT (About ()));
m_pGraphDisplay = new GraphDisplay; m_pGraphDisplay = new GraphDisplay;
QScrollArea *pscroll = new QScrollArea; QScrollArea *pscroll = new QScrollArea;
@ -177,7 +178,8 @@ MainWindow::~MainWindow()
delete m_pluginListDlg; delete m_pluginListDlg;
} }
void MainWindow::AddPlugin() void
MainWindow::AddPlugin ()
{ {
m_pluginListDlg->setGraph (m_pGraph.data ()); m_pluginListDlg->setGraph (m_pGraph.data ());
m_pluginListDlg->show (); m_pluginListDlg->show ();
@ -185,16 +187,15 @@ void MainWindow::AddPlugin()
m_pGraphDisplay->update (info); m_pGraphDisplay->update (info);
} }
void MainWindow::OpenMediaFile() void
MainWindow::OpenMediaFile ()
{ {
QString dir = CustomSettings::lastIODirectory (); QString dir = CustomSettings::lastIODirectory ();
QString path = QFileDialog::getOpenFileName (this, "Open File...", dir); QString path = QFileDialog::getOpenFileName (this, "Open File...", dir);
if(!path.isEmpty()) if (!path.isEmpty ()) {
{
gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (), NULL); gchar *uri = gst_filename_to_uri (path.toStdString ().c_str (), NULL);
if(uri) if (uri) {
{
qDebug () << "Open Source file: " << path; qDebug () << "Open Source file: " << path;
m_pGraph->OpenUri (uri, NULL); m_pGraph->OpenUri (uri, NULL);
@ -209,13 +210,12 @@ void MainWindow::OpenMediaFile()
} }
} }
void
void MainWindow::OpenMediaUri() MainWindow::OpenMediaUri ()
{ {
QString uri = QInputDialog::getText (this, "Open Uri...", "Uri:"); QString uri = QInputDialog::getText (this, "Open Uri...", "Uri:");
if(!uri.isEmpty()) if (!uri.isEmpty ()) {
{
qDebug () << "Open uri: " << uri; qDebug () << "Open uri: " << uri;
m_pGraph->OpenUri (uri.toStdString ().c_str (), NULL); m_pGraph->OpenUri (uri.toStdString ().c_str (), NULL);
@ -225,46 +225,53 @@ void MainWindow::OpenMediaUri()
} }
void MainWindow::Play() void
MainWindow::Play ()
{ {
qDebug () << "Play"; qDebug () << "Play";
m_pGraph->Play (); m_pGraph->Play ();
} }
void MainWindow::Pause() void
MainWindow::Pause ()
{ {
qDebug () << "Pause"; qDebug () << "Pause";
m_pGraph->Pause (); m_pGraph->Pause ();
} }
void MainWindow::Stop() void
MainWindow::Stop ()
{ {
qDebug () << "Stop"; qDebug () << "Stop";
m_pGraph->Stop (); m_pGraph->Stop ();
} }
void MainWindow::Flush() void
MainWindow::Flush ()
{ {
qDebug () << "Flush"; qDebug () << "Flush";
if(m_pGraph -> m_pGraph) if (m_pGraph->m_pGraph) {
{ gst_element_send_event (GST_ELEMENT (m_pGraph->m_pGraph),
gst_element_send_event(GST_ELEMENT(m_pGraph -> m_pGraph), gst_event_new_flush_start()); gst_event_new_flush_start ());
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
gst_element_send_event(GST_ELEMENT(m_pGraph -> m_pGraph), gst_event_new_flush_stop(true)); gst_element_send_event(GST_ELEMENT(m_pGraph -> m_pGraph), gst_event_new_flush_stop(true));
#else #else
gst_element_send_event(GST_ELEMENT(m_pGraph -> m_pGraph), gst_event_new_flush_stop()); gst_element_send_event (GST_ELEMENT (m_pGraph->m_pGraph),
gst_event_new_flush_stop ());
#endif #endif
} }
} }
void MainWindow::ClearGraph() void
MainWindow::ClearGraph ()
{ {
qDebug () << "ClearGraph"; qDebug () << "ClearGraph";
PipelineIE::Clear (m_pGraph); PipelineIE::Clear (m_pGraph);
} }
void MainWindow::Seek(int val) void
MainWindow::Seek (int val)
{ {
if (m_pGraph->SetPosition ((double) (val) / m_pslider->maximum ())) if (m_pGraph->SetPosition ((double) (val) / m_pslider->maximum ()))
qDebug () << "Seek to" << val; qDebug () << "Seek to" << val;
@ -272,16 +279,17 @@ void MainWindow::Seek(int val)
qDebug () << "Seek to" << val << "was FAILED"; qDebug () << "Seek to" << val << "was FAILED";
} }
void MainWindow::timerEvent(QTimerEvent *) void
MainWindow::timerEvent (QTimerEvent *)
{ {
GstState state; GstState state;
GstStateChangeReturn res = gst_element_get_state (m_pGraph -> m_pGraph, &state, NULL, GST_MSECOND); GstStateChangeReturn res = gst_element_get_state (m_pGraph->m_pGraph, &state,
NULL,
GST_MSECOND);
if(res == GST_STATE_CHANGE_SUCCESS) if (res == GST_STATE_CHANGE_SUCCESS) {
{
QString str; QString str;
switch(state) switch (state) {
{
case GST_STATE_VOID_PENDING: case GST_STATE_VOID_PENDING:
str = "Pending"; str = "Pending";
break; break;
@ -301,9 +309,9 @@ void MainWindow::timerEvent(QTimerEvent *)
m_pstatusBar->showMessage (str); m_pstatusBar->showMessage (str);
} }
else else {
{ m_pstatusBar->showMessage (
m_pstatusBar -> showMessage(QString(gst_element_state_change_return_get_name(res))); QString (gst_element_state_change_return_get_name (res)));
} }
double pos = m_pGraph->GetPosition (); double pos = m_pGraph->GetPosition ();
@ -311,33 +319,34 @@ void MainWindow::timerEvent(QTimerEvent *)
if (m_pslider->value () != (int) (m_pslider->maximum () * pos)) if (m_pslider->value () != (int) (m_pslider->maximum () * pos))
m_pslider->setSliderPosition (m_pslider->maximum () * pos); m_pslider->setSliderPosition (m_pslider->maximum () * pos);
m_pGraphDisplay->update (m_pGraph->GetInfo ()); m_pGraphDisplay->update (m_pGraph->GetInfo ());
} }
void MainWindow::Save() void
MainWindow::Save ()
{ {
if (m_fileName.isEmpty ()) if (m_fileName.isEmpty ())
SaveAs (); SaveAs ();
else { else {
QFileInfo fileInfo (m_fileName); QFileInfo fileInfo (m_fileName);
if (fileInfo.completeSuffix().isEmpty() || fileInfo.completeSuffix() != "gpi") if (fileInfo.completeSuffix ().isEmpty ()
|| fileInfo.completeSuffix () != "gpi")
m_fileName = m_fileName + ".gpi"; m_fileName = m_fileName + ".gpi";
PipelineIE::Export (m_pGraph, m_fileName); PipelineIE::Export (m_pGraph, m_fileName);
} }
} }
void MainWindow::SaveAs() void
MainWindow::SaveAs ()
{ {
QString dir = CustomSettings::lastIODirectory (); QString dir = CustomSettings::lastIODirectory ();
QString path = QFileDialog::getSaveFileName(this, "Save As...", dir, tr("*.gpi")); QString path = QFileDialog::getSaveFileName (this, "Save As...", dir,
tr ("*.gpi"));
if(!path.isEmpty()) if (!path.isEmpty ()) {
{
m_fileName = path; m_fileName = path;
Save (); Save ();
@ -346,14 +355,15 @@ void MainWindow::SaveAs()
} }
} }
void MainWindow::Open() void
MainWindow::Open ()
{ {
QString dir = CustomSettings::lastIODirectory (); QString dir = CustomSettings::lastIODirectory ();
QString path = QFileDialog::getOpenFileName(this, "Open...", dir, tr("GPI (*.gpi *.xpm);;All files (*.*)")); QString path = QFileDialog::getOpenFileName (
this, "Open...", dir, tr ("GPI (*.gpi *.xpm);;All files (*.*)"));
if(!path.isEmpty()) if (!path.isEmpty ()) {
{
if (PipelineIE::Import (m_pGraph, path)) if (PipelineIE::Import (m_pGraph, path))
m_fileName = path; m_fileName = path;
@ -362,7 +372,8 @@ void MainWindow::Open()
} }
} }
void MainWindow::About() void
MainWindow::About ()
{ {
QString message; QString message;
message = "<center><b>pipeviz</b></center><br>"; message = "<center><b>pipeviz</b></center><br>";

View file

@ -55,5 +55,4 @@ class MainWindow: public QMainWindow
PluginsListDialog *m_pluginListDlg; PluginsListDialog *m_pluginListDlg;
}; };
#endif #endif

View file

@ -8,12 +8,14 @@
#include <gst/gst.h> #include <gst/gst.h>
PadProperties::PadProperties(QSharedPointer<GraphManager> pGraphManager, const char *elementName, const char *padName, PadProperties::PadProperties (QSharedPointer<GraphManager> pGraphManager,
QWidget *parent, Qt::WindowFlags flags): const char *elementName, const char *padName,
QWidget(parent, flags) QWidget *parent, Qt::WindowFlags flags)
: QWidget (parent, flags)
{ {
setWindowTitle (QString (elementName) + "::" + padName + " properties"); setWindowTitle (QString (elementName) + "::" + padName + " properties");
GstElement *element = gst_bin_get_by_name (GST_BIN(pGraphManager -> m_pGraph), elementName); GstElement *element = gst_bin_get_by_name (GST_BIN (pGraphManager->m_pGraph),
elementName);
if (!element) if (!element)
return; return;
@ -25,7 +27,8 @@ QWidget(parent, flags)
play->addWidget (new QLabel ("Name"), 0, 0); play->addWidget (new QLabel ("Name"), 0, 0);
QLabel *plbl = new QLabel (padName); QLabel *plbl = new QLabel (padName);
plbl -> setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); plbl->setTextInteractionFlags (
Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
play->addWidget (plbl, 0, 1); play->addWidget (plbl, 0, 1);
play->addWidget (new QLabel ("All caps:"), 1, 0); play->addWidget (new QLabel ("All caps:"), 1, 0);
@ -42,10 +45,10 @@ QWidget(parent, flags)
str = noSpecified; str = noSpecified;
plbl = new QLabel (QString (str)); plbl = new QLabel (QString (str));
plbl -> setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); plbl->setTextInteractionFlags (
Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
play->addWidget (plbl, 1, 1); play->addWidget (plbl, 1, 1);
if(caps) if (caps) {
{
g_free (str); g_free (str);
gst_caps_unref (caps); gst_caps_unref (caps);
} }
@ -59,10 +62,10 @@ QWidget(parent, flags)
str = noSpecified; str = noSpecified;
plbl = new QLabel (QString (str)); plbl = new QLabel (QString (str));
plbl -> setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); plbl->setTextInteractionFlags (
Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
play->addWidget (plbl, 2, 1); play->addWidget (plbl, 2, 1);
if(caps) if (caps) {
{
g_free (str); g_free (str);
gst_caps_unref (caps); gst_caps_unref (caps);
} }
@ -80,10 +83,10 @@ QWidget(parent, flags)
str = noSpecified; str = noSpecified;
plbl = new QLabel (QString (str)); plbl = new QLabel (QString (str));
plbl -> setTextInteractionFlags(Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard); plbl->setTextInteractionFlags (
Qt::TextSelectableByMouse | Qt::TextSelectableByKeyboard);
play->addWidget (plbl, 3, 1); play->addWidget (plbl, 3, 1);
if(caps) if (caps) {
{
g_free (str); g_free (str);
gst_caps_unref (caps); gst_caps_unref (caps);
} }

View file

@ -13,5 +13,4 @@ public:
, QWidget *parent = 0, Qt::WindowFlags flags = 0); , QWidget *parent = 0, Qt::WindowFlags flags = 0);
}; };
#endif #endif

View file

@ -9,7 +9,8 @@
#include <QDebug> #include <QDebug>
static void clearPipeline(GstElement *pipeline) static void
clearPipeline (GstElement *pipeline)
{ {
if (!pipeline) if (!pipeline)
return; return;
@ -18,20 +19,18 @@ static void clearPipeline(GstElement *pipeline)
iter = gst_bin_iterate_elements (GST_BIN (pipeline)); iter = gst_bin_iterate_elements (GST_BIN (pipeline));
GstElement *element = NULL; GstElement *element = NULL;
bool done = false; bool done = false;
while (!done) while (!done) {
{
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
GValue value = { 0 }; GValue value =
{ 0};
switch (gst_iterator_next (iter, &value)) switch (gst_iterator_next (iter, &value))
{ {
case GST_ITERATOR_OK: case GST_ITERATOR_OK:
{ {
element = GST_ELEMENT(g_value_get_object(&value)); element = GST_ELEMENT(g_value_get_object(&value));
#else #else
switch (gst_iterator_next (iter, (gpointer *)&element)) switch (gst_iterator_next (iter, (gpointer *) &element)) {
{ case GST_ITERATOR_OK: {
case GST_ITERATOR_OK:
{
#endif #endif
gst_bin_remove (GST_BIN (pipeline), element); gst_bin_remove (GST_BIN (pipeline), element);
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
@ -45,8 +44,7 @@ static void clearPipeline(GstElement *pipeline)
} }
case GST_ITERATOR_DONE: case GST_ITERATOR_DONE:
case GST_ITERATOR_RESYNC: case GST_ITERATOR_RESYNC:
case GST_ITERATOR_ERROR: case GST_ITERATOR_ERROR: {
{
done = true; done = true;
break; break;
} }
@ -67,8 +65,8 @@ namespace
}; };
} }
static void
static void writeProperties(QXmlStreamWriter &xmlWriter, const GstElement *element) writeProperties (QXmlStreamWriter &xmlWriter, const GstElement *element)
{ {
GParamSpec **prop_specs; GParamSpec **prop_specs;
guint num_props; guint num_props;
@ -81,28 +79,23 @@ static void writeProperties(QXmlStreamWriter &xmlWriter, const GstElement *eleme
xmlWriter.writeStartElement ("properties"); xmlWriter.writeStartElement ("properties");
for(std::size_t i = 0; i<num_props; i++) for (std::size_t i = 0; i < num_props; i++) {
{
GParamSpec *param = prop_specs[i]; GParamSpec *param = prop_specs[i];
if((param -> flags & G_PARAM_READABLE) && (param -> flags & G_PARAM_WRITABLE)) if ((param->flags & G_PARAM_READABLE)
{ && (param->flags & G_PARAM_WRITABLE)) {
GValue value = { 0 }; GValue value = { 0 };
g_value_init (&value, param->value_type); g_value_init (&value, param->value_type);
g_object_get_property (G_OBJECT (element), param->name, &value); g_object_get_property (G_OBJECT (element), param->name, &value);
if(!g_param_value_defaults(param, &value)) if (!g_param_value_defaults (param, &value)) {
{
bool skip = false; bool skip = false;
QString propertyName = g_param_spec_get_name (param); QString propertyName = g_param_spec_get_name (param);
QString propertyValue; QString propertyValue;
switch (G_VALUE_TYPE (&value)) {
switch (G_VALUE_TYPE (&value)) case G_TYPE_STRING: {
{
case G_TYPE_STRING:
{
const char *string_val = g_value_get_string (&value); const char *string_val = g_value_get_string (&value);
if (string_val) if (string_val)
@ -111,54 +104,44 @@ static void writeProperties(QXmlStreamWriter &xmlWriter, const GstElement *eleme
skip = true; skip = true;
break; break;
} }
case G_TYPE_BOOLEAN: case G_TYPE_BOOLEAN: {
{
gboolean bool_val = g_value_get_boolean (&value); gboolean bool_val = g_value_get_boolean (&value);
propertyValue = QString::number (bool_val); propertyValue = QString::number (bool_val);
break; break;
} }
case G_TYPE_ULONG: case G_TYPE_ULONG: {
{
propertyValue = QString::number (g_value_get_ulong (&value)); propertyValue = QString::number (g_value_get_ulong (&value));
break; break;
} }
case G_TYPE_LONG: case G_TYPE_LONG: {
{
propertyValue = QString::number (g_value_get_long (&value)); propertyValue = QString::number (g_value_get_long (&value));
break; break;
} }
case G_TYPE_UINT: case G_TYPE_UINT: {
{
propertyValue = QString::number (g_value_get_uint (&value)); propertyValue = QString::number (g_value_get_uint (&value));
break; break;
} }
case G_TYPE_INT: case G_TYPE_INT: {
{
propertyValue = QString::number (g_value_get_int (&value)); propertyValue = QString::number (g_value_get_int (&value));
break; break;
} }
case G_TYPE_UINT64: case G_TYPE_UINT64: {
{
propertyValue = QString::number (g_value_get_uint64 (&value)); propertyValue = QString::number (g_value_get_uint64 (&value));
break; break;
} }
case G_TYPE_INT64: case G_TYPE_INT64: {
{
propertyValue = QString::number (g_value_get_int64 (&value)); propertyValue = QString::number (g_value_get_int64 (&value));
break; break;
} }
case G_TYPE_FLOAT: case G_TYPE_FLOAT: {
{
propertyValue = QString::number (g_value_get_float (&value)); propertyValue = QString::number (g_value_get_float (&value));
break; break;
} }
case G_TYPE_DOUBLE: case G_TYPE_DOUBLE: {
{
propertyValue = QString::number (g_value_get_double (&value)); propertyValue = QString::number (g_value_get_double (&value));
break; break;
} }
default: default: {
{
gchar *elementName = gst_element_get_name (element); gchar *elementName = gst_element_get_name (element);
qDebug () << "property `" << propertyName << "` for `" qDebug () << "property `" << propertyName << "` for `"
@ -170,8 +153,7 @@ static void writeProperties(QXmlStreamWriter &xmlWriter, const GstElement *eleme
} }
}; };
if(!skip) if (!skip) {
{
xmlWriter.writeStartElement ("property"); xmlWriter.writeStartElement ("property");
xmlWriter.writeAttribute ("name", propertyName); xmlWriter.writeAttribute ("name", propertyName);
xmlWriter.writeAttribute ("value", propertyValue); xmlWriter.writeAttribute ("value", propertyValue);
@ -188,25 +170,22 @@ static void writeProperties(QXmlStreamWriter &xmlWriter, const GstElement *eleme
g_free (prop_specs); g_free (prop_specs);
} }
static void
loadProperties (QDomElement node, GstElement *element)
static void loadProperties(QDomElement node, GstElement *element)
{ {
QDomNode child = node.firstChild (); QDomNode child = node.firstChild ();
while(!child.isNull()) while (!child.isNull ()) {
{ if (child.toElement ().tagName () == "property") {
if(child.toElement().tagName() == "property")
{
QString name = child.toElement ().attribute ("name"); QString name = child.toElement ().attribute ("name");
QString value = child.toElement ().attribute ("value"); QString value = child.toElement ().attribute ("value");
GParamSpec *param = g_object_class_find_property(G_OBJECT_GET_CLASS (element), GParamSpec *param = g_object_class_find_property (
name.toStdString().c_str()); G_OBJECT_GET_CLASS (element), name.toStdString ().c_str ());
if(!param) if (!param) {
{
gchar *elementName = gst_element_get_name (element); gchar *elementName = gst_element_get_name (element);
qDebug() << "problem with setting property `" << name << "` for `" << elementName << "`"; qDebug () << "problem with setting property `" << name << "` for `"
<< elementName << "`";
g_free (elementName); g_free (elementName);
continue; continue;
} }
@ -216,71 +195,61 @@ static void loadProperties(QDomElement node, GstElement *element)
std::string tmpStr = name.toStdString (); std::string tmpStr = name.toStdString ();
const char *propName = tmpStr.c_str (); const char *propName = tmpStr.c_str ();
switch (param -> value_type) switch (param->value_type) {
{ case G_TYPE_STRING: {
case G_TYPE_STRING: g_object_set (G_OBJECT (element), propName,
{ value.toStdString ().c_str (), NULL);
g_object_set(G_OBJECT(element), propName, value.toStdString().c_str(), NULL);
break; break;
} }
case G_TYPE_BOOLEAN: case G_TYPE_BOOLEAN: {
{
gboolean val = value.toInt (); gboolean val = value.toInt ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_ULONG: case G_TYPE_ULONG: {
{
gulong val = value.toULong (); gulong val = value.toULong ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_LONG: case G_TYPE_LONG: {
{
glong val = value.toLong (); glong val = value.toLong ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_UINT: case G_TYPE_UINT: {
{
guint val = value.toUInt (); guint val = value.toUInt ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_INT: case G_TYPE_INT: {
{
gint val = value.toInt (); gint val = value.toInt ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_UINT64: case G_TYPE_UINT64: {
{
guint64 val = value.toULongLong (); guint64 val = value.toULongLong ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_INT64: case G_TYPE_INT64: {
{
gint64 val = value.toLongLong (); gint64 val = value.toLongLong ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_FLOAT: case G_TYPE_FLOAT: {
{
gfloat val = value.toFloat (); gfloat val = value.toFloat ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
case G_TYPE_DOUBLE: case G_TYPE_DOUBLE: {
{
gdouble val = value.toDouble (); gdouble val = value.toDouble ();
g_object_set (G_OBJECT (element), propName, val, NULL); g_object_set (G_OBJECT (element), propName, val, NULL);
break; break;
} }
default: default: {
{
gchar *elementName = gst_element_get_name (element); gchar *elementName = gst_element_get_name (element);
qDebug() << "property `" << name << "` for `" << QString(elementName) << "` not supported"; qDebug () << "property `" << name << "` for `"
<< QString (elementName) << "` not supported";
g_free (elementName); g_free (elementName);
break; break;
} }
@ -292,22 +261,26 @@ static void loadProperties(QDomElement node, GstElement *element)
} }
static void
static void create_requst_pad(GstElement *element, const QString &templateName, const QString &padName) create_requst_pad (GstElement *element, const QString &templateName,
const QString &padName)
{ {
GstElementClass *klass = GST_ELEMENT_GET_CLASS (element); GstElementClass *klass = GST_ELEMENT_GET_CLASS (element);
GstPadTemplate *templ = gst_element_class_get_pad_template(klass, templateName.toStdString().c_str()); GstPadTemplate *templ = gst_element_class_get_pad_template (
klass, templateName.toStdString ().c_str ());
gst_element_request_pad(element, templ, padName.toStdString().c_str(), NULL); gst_element_request_pad (element, templ, padName.toStdString ().c_str (),
NULL);
} }
bool PipelineIE::Export(QSharedPointer<GraphManager> pgraph, const QString &fileName) bool
PipelineIE::Export (QSharedPointer<GraphManager> pgraph,
const QString &fileName)
{ {
QFile file (fileName); QFile file (fileName);
if (!file.open(QIODevice::WriteOnly)) if (!file.open (QIODevice::WriteOnly)) {
{
QMessageBox::warning (0, "Read only", "The file is in read only mode"); QMessageBox::warning (0, "Read only", "The file is in read only mode");
return false; return false;
} }
@ -319,28 +292,27 @@ bool PipelineIE::Export(QSharedPointer<GraphManager> pgraph, const QString &file
xmlWriter.writeStartDocument (); xmlWriter.writeStartDocument ();
xmlWriter.writeStartElement ("pipeline"); xmlWriter.writeStartElement ("pipeline");
for(std::size_t i=0; i<info.size(); i++) for (std::size_t i = 0; i < info.size (); i++) {
{
xmlWriter.writeStartElement ("element"); xmlWriter.writeStartElement ("element");
xmlWriter.writeAttribute ("name", info[i].m_name.c_str ()); xmlWriter.writeAttribute ("name", info[i].m_name.c_str ());
xmlWriter.writeAttribute ("plugin-name", info[i].m_pluginName.c_str ()); xmlWriter.writeAttribute ("plugin-name", info[i].m_pluginName.c_str ());
GstElement *element = gst_bin_get_by_name (GST_BIN(pgraph -> m_pGraph), info[i].m_name.c_str()); GstElement *element = gst_bin_get_by_name (GST_BIN (pgraph->m_pGraph),
info[i].m_name.c_str ());
for(std::size_t j=0; j<info[i].m_pads.size(); j++) for (std::size_t j = 0; j < info[i].m_pads.size (); j++) {
{
xmlWriter.writeStartElement ("pad"); xmlWriter.writeStartElement ("pad");
xmlWriter.writeAttribute ("name", info[i].m_pads[j].m_name.c_str ()); xmlWriter.writeAttribute ("name", info[i].m_pads[j].m_name.c_str ());
GstPad *pad = gst_element_get_static_pad(element, info[i].m_pads[j].m_name.c_str()); GstPad *pad = gst_element_get_static_pad (
element, info[i].m_pads[j].m_name.c_str ());
GstPadTemplate *templ = gst_pad_get_pad_template (pad); GstPadTemplate *templ = gst_pad_get_pad_template (pad);
if (templ) { if (templ) {
QString presence; QString presence;
switch(GST_PAD_TEMPLATE_PRESENCE(templ)) switch (GST_PAD_TEMPLATE_PRESENCE (templ)) {
{
case GST_PAD_ALWAYS: case GST_PAD_ALWAYS:
presence = "always"; presence = "always";
break; break;
@ -355,35 +327,38 @@ bool PipelineIE::Export(QSharedPointer<GraphManager> pgraph, const QString &file
}; };
xmlWriter.writeAttribute ("presence", presence); xmlWriter.writeAttribute ("presence", presence);
xmlWriter.writeAttribute("template-name", GST_PAD_TEMPLATE_NAME_TEMPLATE(templ)); xmlWriter.writeAttribute ("template-name",
} else { GST_PAD_TEMPLATE_NAME_TEMPLATE (templ));
qDebug() << "Unable to find a template for" << info[i].m_pads[j].m_name.c_str(); }
else {
qDebug () << "Unable to find a template for"
<< info[i].m_pads[j].m_name.c_str ();
xmlWriter.writeAttribute ("presence", "always"); xmlWriter.writeAttribute ("presence", "always");
xmlWriter.writeAttribute ("template-name", ""); xmlWriter.writeAttribute ("template-name", "");
} }
gst_object_unref (pad); gst_object_unref (pad);
if(info[i].m_connections[j].m_elementId != (size_t)-1 && if (info[i].m_connections[j].m_elementId != (size_t) -1
info[i].m_connections[j].m_padId != (size_t)-1) && info[i].m_connections[j].m_padId != (size_t) -1) {
{
std::size_t elementPos, padPos; std::size_t elementPos, padPos;
for(elementPos = 0; elementPos < info.size(); elementPos++) for (elementPos = 0; elementPos < info.size (); elementPos++) {
{ if (info[elementPos].m_id == info[i].m_connections[j].m_elementId) {
if(info[elementPos].m_id == info[i].m_connections[j].m_elementId)
{
for (padPos = 0; padPos < info[elementPos].m_pads.size (); padPos++) for (padPos = 0; padPos < info[elementPos].m_pads.size (); padPos++)
if(info[elementPos].m_pads[padPos].m_id == info[i].m_connections[j].m_padId) if (info[elementPos].m_pads[padPos].m_id
== info[i].m_connections[j].m_padId)
break; break;
if (padPos < info[elementPos].m_pads.size ()) if (padPos < info[elementPos].m_pads.size ())
break; break;
} }
} }
if(elementPos < info.size() && padPos < info[elementPos].m_pads.size()) if (elementPos < info.size ()
{ && padPos < info[elementPos].m_pads.size ()) {
xmlWriter.writeStartElement ("connected-to"); xmlWriter.writeStartElement ("connected-to");
xmlWriter.writeAttribute("element-name", info[elementPos].m_name.c_str()); xmlWriter.writeAttribute ("element-name",
xmlWriter.writeAttribute("pad-name", info[elementPos].m_pads[padPos].m_name.c_str()); info[elementPos].m_name.c_str ());
xmlWriter.writeAttribute (
"pad-name", info[elementPos].m_pads[padPos].m_name.c_str ());
xmlWriter.writeEndElement (); xmlWriter.writeEndElement ();
} }
} }
@ -403,16 +378,16 @@ bool PipelineIE::Export(QSharedPointer<GraphManager> pgraph, const QString &file
return true; return true;
} }
bool
bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &fileName) PipelineIE::Import (QSharedPointer<GraphManager> pgraph,
const QString &fileName)
{ {
GstElement *pipeline = pgraph->m_pGraph; GstElement *pipeline = pgraph->m_pGraph;
QFile file (fileName); QFile file (fileName);
if(!file.open(QFile::ReadOnly | QFile::Text)) if (!file.open (QFile::ReadOnly | QFile::Text)) {
{ QMessageBox::warning (
QMessageBox::warning(0, "Open failed", 0, "Open failed",
QString("Cannot read file ") + fileName + QString ("Cannot read file ") + fileName + ": " + file.errorString ());
": " + file.errorString());
return false; return false;
} }
@ -422,9 +397,9 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
int errorColumn; int errorColumn;
QDomDocument doc; QDomDocument doc;
if(!doc.setContent(&file, false, &errorStr, &errorLine, &errorColumn)) if (!doc.setContent (&file, false, &errorStr, &errorLine, &errorColumn)) {
{ QMessageBox::warning (
QMessageBox::warning(0, "Xml parsing failed", 0, "Xml parsing failed",
QString ("Parse error at line ") + QString::number (errorLine) + ", " QString ("Parse error at line ") + QString::number (errorLine) + ", "
"column " + QString::number (errorColumn) + ": " + errorStr); "column " + QString::number (errorColumn) + ": " + errorStr);
return false; return false;
@ -434,8 +409,7 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
QDomElement root = doc.documentElement (); QDomElement root = doc.documentElement ();
if(root.tagName() != "pipeline") if (root.tagName () != "pipeline") {
{
QMessageBox::warning (0, "Parsing failed", "Is invalid pipeline file"); QMessageBox::warning (0, "Parsing failed", "Is invalid pipeline file");
return false; return false;
} }
@ -443,22 +417,21 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
QDomNode child = root.firstChild (); QDomNode child = root.firstChild ();
std::vector<Connection> connections; std::vector<Connection> connections;
while(!child.isNull()) while (!child.isNull ()) {
{ if (child.toElement ().tagName () == "element") {
if(child.toElement().tagName() == "element")
{
QDomElement elNode = child.toElement (); QDomElement elNode = child.toElement ();
GstElement *pel = gst_element_factory_make (
GstElement *pel = gst_element_factory_make(elNode.attribute("plugin-name").toStdString().c_str(), elNode.attribute ("plugin-name").toStdString ().c_str (),
elNode.attribute ("name").toStdString ().c_str ()); elNode.attribute ("name").toStdString ().c_str ());
if(!pel) if (!pel) {
{ QMessageBox::warning (
QMessageBox::warning(0, "Element creation failed", 0,
QString("Could not create element of `") + "Element creation failed",
elNode.attribute("plugin-name") + "` with name `" + QString ("Could not create element of `")
elNode.attribute("name") + "`"); + elNode.attribute ("plugin-name") + "` with name `"
+ elNode.attribute ("name") + "`");
child = child.nextSibling (); child = child.nextSibling ();
continue; continue;
@ -466,11 +439,12 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
bool res = gst_bin_add (GST_BIN (pipeline), pel); bool res = gst_bin_add (GST_BIN (pipeline), pel);
if(!res) if (!res) {
{ QMessageBox::warning (
QMessageBox::warning(0, "Element insertion failed", 0,
QString("Could not insert element `") + "Element insertion failed",
elNode.attribute("name") + "` to pipeline"); QString ("Could not insert element `") + elNode.attribute ("name")
+ "` to pipeline");
child = child.nextSibling (); child = child.nextSibling ();
continue; continue;
@ -478,51 +452,54 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
gst_element_sync_state_with_parent (pel); gst_element_sync_state_with_parent (pel);
QDomNode elementChild = elNode.firstChild (); QDomNode elementChild = elNode.firstChild ();
while(!elementChild.isNull()) while (!elementChild.isNull ()) {
{ if (elementChild.toElement ().tagName () == "pad") {
if(elementChild.toElement().tagName() == "pad")
{
QDomNode padChild = elementChild.firstChild (); QDomNode padChild = elementChild.firstChild ();
QDomElement elPad = elementChild.toElement (); QDomElement elPad = elementChild.toElement ();
// GstPadPresence presence = GST_PAD_ALWAYS; // GstPadPresence presence = GST_PAD_ALWAYS;
QString templaneName; QString templaneName;
if (elPad.attribute ("presence") == "request") if (elPad.attribute ("presence") == "request")
create_requst_pad(pel, elPad.attribute("template-name"), elPad.attribute("name")); create_requst_pad (pel, elPad.attribute ("template-name"),
elPad.attribute ("name"));
while(!padChild.isNull()) while (!padChild.isNull ()) {
{ if (padChild.toElement ().tagName () == "connected-to") {
if(padChild.toElement().tagName() == "connected-to")
{
bool isExists = false; bool isExists = false;
QDomElement elCoonnectedTo = padChild.toElement (); QDomElement elCoonnectedTo = padChild.toElement ();
for(std::size_t i=0; i<connections.size(); i++) for (std::size_t i = 0; i < connections.size (); i++) {
{ if ((connections[i].element1
if((connections[i].element1 == elNode.attribute("name").toStdString() && == elNode.attribute ("name").toStdString ()
connections[i].element2 == elCoonnectedTo.attribute("element-name").toStdString() && && connections[i].element2
connections[i].pad1 == elPad.attribute("name").toStdString() && == elCoonnectedTo.attribute ("element-name").toStdString ()
connections[i].pad2 == elCoonnectedTo.attribute("pad-name").toStdString()) && connections[i].pad1
|| == elPad.attribute ("name").toStdString ()
(connections[i].element2 == elNode.attribute("name").toStdString() && && connections[i].pad2
connections[i].element1 == elCoonnectedTo.attribute("element-name").toStdString() && == elCoonnectedTo.attribute ("pad-name").toStdString ())
connections[i].pad2 == elPad.attribute("name").toStdString() && || (connections[i].element2
connections[i].pad1 ==elCoonnectedTo.attribute("pad-name").toStdString()) == elNode.attribute ("name").toStdString ()
) && connections[i].element1
{ == elCoonnectedTo.attribute ("element-name").toStdString ()
&& connections[i].pad2
== elPad.attribute ("name").toStdString ()
&& connections[i].pad1
== elCoonnectedTo.attribute ("pad-name").toStdString ())) {
isExists = true; isExists = true;
} }
} }
if(!isExists) if (!isExists) {
{
Connection newConnetion; Connection newConnetion;
newConnetion.element1 = elNode.attribute("name").toStdString(); newConnetion.element1 =
newConnetion.element2 = padChild.toElement().attribute("element-name").toStdString(); elNode.attribute ("name").toStdString ();
newConnetion.pad1 = elementChild.toElement().attribute("name").toStdString(); newConnetion.element2 = padChild.toElement ().attribute (
newConnetion.pad2 = padChild.toElement().attribute("pad-name").toStdString(); "element-name").toStdString ();
newConnetion.pad1 =
elementChild.toElement ().attribute ("name").toStdString ();
newConnetion.pad2 =
padChild.toElement ().attribute ("pad-name").toStdString ();
connections.push_back (newConnetion); connections.push_back (newConnetion);
} }
@ -530,8 +507,7 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
padChild = padChild.nextSibling (); padChild = padChild.nextSibling ();
} }
} }
else if(elementChild.toElement().tagName() == "properties") else if (elementChild.toElement ().tagName () == "properties") {
{
loadProperties (elementChild.toElement (), pel); loadProperties (elementChild.toElement (), pel);
} }
elementChild = elementChild.nextSibling (); elementChild = elementChild.nextSibling ();
@ -542,28 +518,28 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
std::size_t maxStarts = 5; std::size_t maxStarts = 5;
bool setReady = true; bool setReady = true;
for(std::size_t k=0; k<maxStarts; k++) for (std::size_t k = 0; k < maxStarts; k++) {
{
if (connections.empty ()) if (connections.empty ())
break; break;
if (k > 0) if (k > 0)
setReady = false; setReady = false;
while(true) while (true) {
{
std::size_t i = 0; std::size_t i = 0;
for(; i<connections.size(); i++) for (; i < connections.size (); i++) {
{ GstElement *el1 = gst_bin_get_by_name (
GstElement *el1 = gst_bin_get_by_name (GST_BIN(pipeline), connections[i].element1.c_str()); GST_BIN (pipeline), connections[i].element1.c_str ());
GstElement *el2 = gst_bin_get_by_name (GST_BIN(pipeline), connections[i].element2.c_str()); GstElement *el2 = gst_bin_get_by_name (
GST_BIN (pipeline), connections[i].element2.c_str ());
if(!el1 || !el2) if (!el1 || !el2) {
{ QMessageBox::warning (
QMessageBox::warning(0, "Internal error", 0,
QString("Could not find one of elements `") + "Internal error",
QString(connections[i].element1.c_str()) + "`, `" + QString ("Could not find one of elements `")
QString(connections[i].element2.c_str()) + "`"); + QString (connections[i].element1.c_str ()) + "`, `"
+ QString (connections[i].element2.c_str ()) + "`");
gst_object_unref (el1); gst_object_unref (el1);
gst_object_unref (el2); gst_object_unref (el2);
@ -571,15 +547,18 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
return false; return false;
} }
GstPad *pad1 = gst_element_get_static_pad(el1, connections[i].pad1.c_str()); GstPad *pad1 = gst_element_get_static_pad (
GstPad *pad2 = gst_element_get_static_pad(el2, connections[i].pad2.c_str()); el1, connections[i].pad1.c_str ());
GstPad *pad2 = gst_element_get_static_pad (
el2, connections[i].pad2.c_str ());
if(pad1 && pad2) if (pad1 && pad2) {
{
if (GST_PAD_IS_SRC (pad1)) if (GST_PAD_IS_SRC (pad1))
gst_element_link_pads(el1, connections[i].pad1.c_str(), el2, connections[i].pad2.c_str()); gst_element_link_pads (el1, connections[i].pad1.c_str (), el2,
connections[i].pad2.c_str ());
else else
gst_element_link_pads(el2, connections[i].pad2.c_str(), el1, connections[i].pad1.c_str()); gst_element_link_pads (el2, connections[i].pad2.c_str (), el1,
connections[i].pad1.c_str ());
gst_object_unref (pad1); gst_object_unref (pad1);
gst_object_unref (pad2); gst_object_unref (pad2);
@ -605,8 +584,7 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
break; break;
} }
if(!connections.empty()) if (!connections.empty ()) {
{
gst_element_set_state (pipeline, GST_STATE_PAUSED); gst_element_set_state (pipeline, GST_STATE_PAUSED);
GstState state; GstState state;
@ -621,7 +599,8 @@ bool PipelineIE::Import(QSharedPointer<GraphManager> pgraph, const QString &file
return true; return true;
} }
bool PipelineIE::Clear(QSharedPointer<GraphManager> pgraph) bool
PipelineIE::Clear (QSharedPointer<GraphManager> pgraph)
{ {
GstElement *pipeline = pgraph->m_pGraph; GstElement *pipeline = pgraph->m_pGraph;
clearPipeline (pipeline); clearPipeline (pipeline);

View file

@ -14,7 +14,8 @@
#include <QDebug> #include <QDebug>
static gint plugins_sort_cb (gconstpointer a, gconstpointer b) static gint
plugins_sort_cb (gconstpointer a, gconstpointer b)
{ {
Plugin* p1 = (Plugin*) a; Plugin* p1 = (Plugin*) a;
Plugin* p2 = (Plugin*) b; Plugin* p2 = (Plugin*) b;
@ -23,7 +24,8 @@ static gint plugins_sort_cb (gconstpointer a, gconstpointer b)
return 1; return 1;
else if (p1->getRank () == p2->getRank ()) { else if (p1->getRank () == p2->getRank ()) {
return 0; return 0;
} else { }
else {
return -1; return -1;
} }
} }
@ -38,7 +40,8 @@ PluginsList::~PluginsList()
//g_list_free(m_pluginsList); //g_list_free(m_pluginsList);
} }
void PluginsList::init() void
PluginsList::init ()
{ {
std::size_t num = 0; std::size_t num = 0;
GList *plugins; GList *plugins;
@ -50,8 +53,7 @@ void PluginsList::init()
registry = gst_registry_get_default (); registry = gst_registry_get_default ();
#endif #endif
plugins = gst_registry_get_plugin_list (registry); plugins = gst_registry_get_plugin_list (registry);
while(plugins) while (plugins) {
{
GstPlugin *plugin; GstPlugin *plugin;
plugin = (GstPlugin *) (plugins->data); plugin = (GstPlugin *) (plugins->data);
plugins = g_list_next (plugins); plugins = g_list_next (plugins);
@ -60,15 +62,13 @@ void PluginsList::init()
#else #else
registry = gst_registry_get_default (); registry = gst_registry_get_default ();
#endif #endif
GList *features = gst_registry_get_feature_list_by_plugin (registry, GList *features = gst_registry_get_feature_list_by_plugin (
gst_plugin_get_name (plugin)); registry, gst_plugin_get_name (plugin));
while(features) while (features) {
{
GstPluginFeature *feature; GstPluginFeature *feature;
feature = GST_PLUGIN_FEATURE (features->data); feature = GST_PLUGIN_FEATURE (features->data);
if(GST_IS_ELEMENT_FACTORY (feature)) if (GST_IS_ELEMENT_FACTORY (feature)) {
{
GstElementFactory *factory; GstElementFactory *factory;
factory = GST_ELEMENT_FACTORY (feature); factory = GST_ELEMENT_FACTORY (feature);
int rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)); int rank = gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory));
@ -82,25 +82,30 @@ void PluginsList::init()
} }
} }
GList* PluginsList::getSortedByRank() GList*
PluginsList::getSortedByRank ()
{ {
GList* sorted_list = g_list_sort (m_pluginsList, plugins_sort_cb); GList* sorted_list = g_list_sort (m_pluginsList, plugins_sort_cb);
return sorted_list; return sorted_list;
} }
GList* PluginsList::getPluginListByCaps(GstPadDirection direction, GstCaps* caps) GList*
PluginsList::getPluginListByCaps (GstPadDirection direction, GstCaps* caps)
{ {
GList * caps_plugins_list = NULL; GList * caps_plugins_list = NULL;
GList *l, *p; GList *l, *p;
for (l = m_pluginsList; l != NULL; l = l->next) { for (l = m_pluginsList; l != NULL; l = l->next) {
Plugin* plugin = (Plugin*) (l->data); Plugin* plugin = (Plugin*) (l->data);
GstElementFactory* factory = gst_element_factory_find(plugin->getName().toStdString().c_str()); GstElementFactory* factory = gst_element_factory_find (
plugin->getName ().toStdString ().c_str ());
if (factory) { if (factory) {
const GList* pads = gst_element_factory_get_static_pad_templates(factory); const GList* pads = gst_element_factory_get_static_pad_templates (
factory);
for (p = (GList*) pads; p != NULL; p = p->next) { for (p = (GList*) pads; p != NULL; p = p->next) {
GstStaticPadTemplate* padTemplate = (GstStaticPadTemplate*) (p->data); GstStaticPadTemplate* padTemplate = (GstStaticPadTemplate*) (p->data);
if (padTemplate->direction == direction && gst_caps_can_intersect(caps, padTemplate->static_caps.caps)) if (padTemplate->direction == direction
&& gst_caps_can_intersect (caps, padTemplate->static_caps.caps))
caps_plugins_list = g_list_append (caps_plugins_list, plugin); caps_plugins_list = g_list_append (caps_plugins_list, plugin);
} }
} }
@ -108,10 +113,11 @@ GList* PluginsList::getPluginListByCaps(GstPadDirection direction, GstCaps* caps
return caps_plugins_list; return caps_plugins_list;
} }
PluginsListDialog::PluginsListDialog(PluginsList* pluginList, QWidget *pwgt, Qt::WindowFlags f): PluginsListDialog::PluginsListDialog (PluginsList* pluginList, QWidget *pwgt,
QDialog(pwgt, f) Qt::WindowFlags f)
, m_pPluginsList(pluginList) : QDialog (pwgt, f),
, m_pGraph(NULL) m_pPluginsList (pluginList),
m_pGraph (NULL)
{ {
m_pPlugins = new QListWidget; m_pPlugins = new QListWidget;
m_pPlugins->setSortingEnabled (true); m_pPlugins->setSortingEnabled (true);
@ -163,23 +169,24 @@ PluginsListDialog::~PluginsListDialog()
delete m_pPluginsList; delete m_pPluginsList;
} }
void PluginsListDialog::showInfo(QListWidgetItem *pitem, QListWidgetItem *previous) void
PluginsListDialog::showInfo (QListWidgetItem *pitem, QListWidgetItem *previous)
{ {
qDebug () << "Show Info: " << pitem->text (); qDebug () << "Show Info: " << pitem->text ();
m_plblInfo->clear (); m_plblInfo->clear ();
QString descr; QString descr;
descr += "<b>Plugin details</b><hr>"; descr += "<b>Plugin details</b><hr>";
GstElementFactory *factory = gst_element_factory_find(pitem -> text().toStdString().c_str()); GstElementFactory *factory = gst_element_factory_find (
if(!factory) pitem->text ().toStdString ().c_str ());
{ if (!factory) {
qDebug () << "warning: " << pitem->text () << " Not Found"; qDebug () << "warning: " << pitem->text () << " Not Found";
return; return;
} }
factory = GST_ELEMENT_FACTORY (gst_plugin_feature_load (GST_PLUGIN_FEATURE(factory))); factory = GST_ELEMENT_FACTORY (
if(!factory) gst_plugin_feature_load (GST_PLUGIN_FEATURE (factory)));
{ if (!factory) {
qDebug () << "warning: " << pitem->text () << " Not Found"; qDebug () << "warning: " << pitem->text () << " Not Found";
return; return;
} }
@ -192,8 +199,7 @@ void PluginsListDialog::showInfo(QListWidgetItem *pitem, QListWidgetItem *previo
} }
GstPlugin* plugin = gst_default_registry_find_plugin (plugin_name); GstPlugin* plugin = gst_default_registry_find_plugin (plugin_name);
#endif #endif
if(!plugin) if (!plugin) {
{
qDebug () << "warning: " << pitem->text () << " Not Found"; qDebug () << "warning: " << pitem->text () << " Not Found";
return; return;
} }
@ -201,45 +207,54 @@ void PluginsListDialog::showInfo(QListWidgetItem *pitem, QListWidgetItem *previo
#if GST_VERSION_MAJOR >= 1 #if GST_VERSION_MAJOR >= 1
const gchar *release_date = gst_plugin_get_release_date_string (plugin); const gchar *release_date = gst_plugin_get_release_date_string (plugin);
#else #else
const gchar *release_date = (plugin->desc.release_datetime) ? plugin->desc.release_datetime : ""; const gchar *release_date =
(plugin->desc.release_datetime) ? plugin->desc.release_datetime : "";
#endif #endif
const gchar *filename = gst_plugin_get_filename (plugin); const gchar *filename = gst_plugin_get_filename (plugin);
descr += "<b>Name</b>: " + QString (gst_plugin_get_name (plugin)) + "<br>"; descr += "<b>Name</b>: " + QString (gst_plugin_get_name (plugin)) + "<br>";
descr += "<b>Description</b>: " + QString(gst_plugin_get_description(plugin)) + "<br>"; descr += "<b>Description</b>: "
descr += "<b>Filename</b>: " + QString((filename != NULL) ? filename : "(null)") + "<br>"; + QString (gst_plugin_get_description (plugin)) + "<br>";
descr += "<b>Version</b>: " + QString(gst_plugin_get_version (plugin)) + "<br>"; descr += "<b>Filename</b>: "
descr += "<b>License</b>: " + QString(gst_plugin_get_license (plugin)) + "<br>"; + QString ((filename != NULL) ? filename : "(null)") + "<br>";
descr += "<b>Source module</b>: " + QString(gst_plugin_get_source (plugin)) + "<br>"; descr += "<b>Version</b>: " + QString (gst_plugin_get_version (plugin))
+ "<br>";
descr += "<b>License</b>: " + QString (gst_plugin_get_license (plugin))
+ "<br>";
descr += "<b>Source module</b>: " + QString (gst_plugin_get_source (plugin))
+ "<br>";
if (release_date != NULL) if (release_date != NULL) {
{
const gchar *tz = "(UTC)"; const gchar *tz = "(UTC)";
gchar *str, *sep; gchar *str, *sep;
str = g_strdup (release_date); str = g_strdup (release_date);
sep = strstr (str, "T"); sep = strstr (str, "T");
if (sep != NULL) if (sep != NULL) {
{
*sep = ' '; *sep = ' ';
sep = strstr (sep + 1, "Z"); sep = strstr (sep + 1, "Z");
if (sep != NULL) if (sep != NULL)
*sep = ' '; *sep = ' ';
} }
else else {
{
tz = ""; tz = "";
} }
descr += "<b>Source release date</b>: " + QString(str) + " " + QString(tz) + "<br>"; descr += "<b>Source release date</b>: " + QString (str) + " " + QString (tz)
+ "<br>";
g_free (str); g_free (str);
} }
descr += "<b>Binary package</b>: " + QString(gst_plugin_get_package (plugin)) + "<br>"; descr += "<b>Binary package</b>: " + QString (gst_plugin_get_package (plugin))
descr += "<b>Origin URL</b>: " + QString(gst_plugin_get_origin (plugin)) + "<br>"; + "<br>";
descr += "<b>Rank</b>: " + QString::number(gst_plugin_feature_get_rank(GST_PLUGIN_FEATURE(factory))); descr += "<b>Origin URL</b>: " + QString (gst_plugin_get_origin (plugin))
+ "<br>";
descr += "<b>Rank</b>: "
+ QString::number (
gst_plugin_feature_get_rank (GST_PLUGIN_FEATURE (factory)));
m_plblInfo->setText (descr); m_plblInfo->setText (descr);
} }
void PluginsListDialog::insert(QListWidgetItem *pitem) void
PluginsListDialog::insert (QListWidgetItem *pitem)
{ {
if (!pitem) { if (!pitem) {
qDebug () << "Do not insert null item"; qDebug () << "Do not insert null item";
@ -247,22 +262,24 @@ void PluginsListDialog::insert(QListWidgetItem *pitem)
} }
qDebug () << "Insert: " << pitem->text (); qDebug () << "Insert: " << pitem->text ();
if(!m_pGraph || !m_pGraph -> AddPlugin(pitem -> text().toStdString().c_str(), NULL)) if (!m_pGraph
{ || !m_pGraph->AddPlugin (pitem->text ().toStdString ().c_str (), NULL)) {
QMessageBox::warning(this, "Plugin addition problem", "Plugin `" + pitem -> text() + "` insertion was FAILED"); QMessageBox::warning (
this, "Plugin addition problem",
"Plugin `" + pitem->text () + "` insertion was FAILED");
qDebug () << "Plugin `" << pitem->text () << "` insertion FAILED"; qDebug () << "Plugin `" << pitem->text () << "` insertion FAILED";
return; return;
} }
} }
bool PluginsListDialog::eventFilter(QObject *obj, QEvent *event) bool
{ PluginsListDialog::eventFilter (QObject *obj, QEvent *event)
if (event -> type() == QEvent::KeyPress)
{ {
if (event->type () == QEvent::KeyPress) {
QKeyEvent *key = static_cast<QKeyEvent*> (event); QKeyEvent *key = static_cast<QKeyEvent*> (event);
if((key -> key() == Qt::Key_Enter) || (key -> key() == Qt::Key_Return) && m_pPlugins -> currentItem()) if ((key->key () == Qt::Key_Enter)
{ || (key->key () == Qt::Key_Return) && m_pPlugins->currentItem ()) {
insert (m_pPlugins->currentItem ()); insert (m_pPlugins->currentItem ());
return true; return true;
} }
@ -271,10 +288,10 @@ bool PluginsListDialog::eventFilter(QObject *obj, QEvent *event)
return QDialog::eventFilter (obj, event); return QDialog::eventFilter (obj, event);
} }
void PluginsListDialog::filterPlagins(const QString &text) void
{ PluginsListDialog::filterPlagins (const QString &text)
for(std::size_t i=0; i<m_pPlugins -> count(); i++)
{ {
for (std::size_t i = 0; i < m_pPlugins->count (); i++) {
QListWidgetItem *pitem = m_pPlugins->item (i); QListWidgetItem *pitem = m_pPlugins->item (i);
if (pitem->text ().contains (text)) if (pitem->text ().contains (text))
@ -284,7 +301,8 @@ void PluginsListDialog::filterPlagins(const QString &text)
} }
} }
void PluginsListDialog::InitPluginsList() void
PluginsListDialog::InitPluginsList ()
{ {
if (!m_pPluginsList) if (!m_pPluginsList)
m_pPluginsList = new PluginsList (); m_pPluginsList = new PluginsList ();

View file

@ -5,10 +5,8 @@
#include <QLabel> #include <QLabel>
#include <QListWidgetItem> #include <QListWidgetItem>
#include "GraphManager.h" #include "GraphManager.h"
class Plugin class Plugin
{ {
public: public:
@ -42,7 +40,6 @@ private:
GList* m_pluginsList; GList* m_pluginsList;
}; };
class PluginsListDialog: public QDialog class PluginsListDialog: public QDialog
{ {
Q_OBJECT Q_OBJECT
@ -72,7 +69,4 @@ private:
GraphManager *m_pGraph; GraphManager *m_pGraph;
}; };
#endif #endif

View file

@ -1,16 +1,19 @@
#include "SeekSlider.h" #include "SeekSlider.h"
void SeekSlider::mousePressEvent(QMouseEvent *event) void
{ SeekSlider::mousePressEvent (QMouseEvent *event)
if(event->button() == Qt::LeftButton)
{ {
if (event->button () == Qt::LeftButton) {
if (orientation () == Qt::Vertical) if (orientation () == Qt::Vertical)
setValue(minimum() + ((maximum()-minimum()) * (height()-event->y())) / height() ) ; setValue (minimum ()
+ ((maximum () - minimum ()) * (height () - event->y ())) / height ());
else else
setValue(minimum() + ((maximum()-minimum()) * event->x()) / width() ) ; setValue (minimum ()
+ ((maximum () - minimum ()) * event->x ()) / width ());
event->accept (); event->accept ();
} }
QSlider::mousePressEvent (event); QSlider::mousePressEvent (event);
}; }
;

View file

@ -1,7 +1,6 @@
#ifndef SEEK_SLIDER_H_ #ifndef SEEK_SLIDER_H_
#define SEEK_SLIDER_H_ #define SEEK_SLIDER_H_
#include <QSlider> #include <QSlider>
#include <QMouseEvent> #include <QMouseEvent>
@ -11,6 +10,4 @@ class SeekSlider: public QSlider
void mousePressEvent(QMouseEvent *); void mousePressEvent(QMouseEvent *);
}; };
#endif #endif

View file

@ -3,7 +3,8 @@
#include <gst/gst.h> #include <gst/gst.h>
int main(int argc, char **argv) int
main (int argc, char **argv)
{ {
gst_init (&argc, &argv); gst_init (&argc, &argv);