Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,87 @@ void TestMythGenericTree::test_state(void)
QCOMPARE(QString("tres"), node.GetState("three"));
}

static QString test_cb_fn(const QString &name, void *data)
{
Q_UNUSED(data);
if (name == QStringLiteral("key2"))
return QStringLiteral("beta");
if (name == QStringLiteral("key3"))
return QStringLiteral("gamma");
if (name == QStringLiteral("two"))
return QStringLiteral("dos");
if (name == QStringLiteral("three"))
return QStringLiteral("tres");
return QString();
}

void TestMythGenericTree::test_text_cb(void)
{
MythGenericTree node("title");
node.SetTextCb(test_cb_fn, nullptr);

QCOMPARE(QString("title"), node.GetText());

node.SetText("new title");
QCOMPARE(QString("new title"), node.GetText());

node.SetText("alpha", "key1");
QCOMPARE(QString("alpha"), node.GetText("key1"));
QCOMPARE(QString("beta"), node.GetText("key2"));
QCOMPARE(QString("gamma"), node.GetText("key3"));

node.SetText("delta", "key1");
QCOMPARE(QString("delta"), node.GetText("key1"));

InfoMap map = {{"one", "uno"}};
node.SetTextFromMap(map);
QCOMPARE(QString("uno"), node.GetText("one"));
QCOMPARE(QString("dos"), node.GetText("two"));
QCOMPARE(QString("tres"), node.GetText("three"));
}

void TestMythGenericTree::test_image_cb(void)
{
MythGenericTree node("no title");

node.SetImageCb(test_cb_fn, nullptr);

node.SetImage("alpha", "key1");
QCOMPARE(QString("alpha"), node.GetImage("key1"));
QCOMPARE(QString("beta"), node.GetImage("key2"));
QCOMPARE(QString("gamma"), node.GetImage("key3"));

node.SetImage("delta", "key1");
QCOMPARE(QString("delta"), node.GetImage("key1"));

InfoMap map = {{"one", "uno"}};
node.SetImageFromMap(map);
QCOMPARE(QString("uno"), node.GetImage("one"));
QCOMPARE(QString("dos"), node.GetImage("two"));
QCOMPARE(QString("tres"), node.GetImage("three"));
}

void TestMythGenericTree::test_state_cb(void)
{
MythGenericTree node("no title");

node.SetStateCb(test_cb_fn, nullptr);

node.DisplayState("alpha", "key1");
QCOMPARE(QString("alpha"), node.GetState("key1"));
QCOMPARE(QString("beta"), node.GetState("key2"));
QCOMPARE(QString("gamma"), node.GetState("key3"));

node.DisplayState("delta", "key1");
QCOMPARE(QString("delta"), node.GetState("key1"));

InfoMap map = {{"one", "uno"}};
node.DisplayStateFromMap(map);
QCOMPARE(QString("uno"), node.GetState("one"));
QCOMPARE(QString("dos"), node.GetState("two"));
QCOMPARE(QString("tres"), node.GetState("three"));
}

void TestMythGenericTree::cleanupTestCase()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,10 @@ private slots:
static void test_text(void);
static void test_image(void);
static void test_state(void);

static void test_text_cb(void);
static void test_image_cb(void);
static void test_state_cb(void);

static void cleanupTestCase();
};
21 changes: 5 additions & 16 deletions mythtv/programs/mythfrontend/videolist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -301,31 +301,20 @@ int AddFileNode(MythGenericTree *where_to_add, const QString& name,
{
MythGenericTree *sub_node = where_to_add->addNode(name, 0, true);
sub_node->SetData(QVariant::fromValue(TreeNodeData(metadata)));

// Text
InfoMap textMap;
metadata->toMap(textMap);
sub_node->SetTextFromMap(textMap);

// Images
InfoMap imageMap;
metadata->GetImageMap(imageMap);
sub_node->SetImageFromMap(imageMap);
sub_node->SetImage("buttonimage", imageMap["smartimage"]);
sub_node->SetTextCb( &VideoMetadata::MetadataGetTextCb, metadata);
sub_node->SetImageCb(&VideoMetadata::MetadataGetImageCb, metadata);
sub_node->SetStateCb(&VideoMetadata::MetadataGetStateCb, metadata);

// Assign images to parent node if this is the first child
if (where_to_add->visibleChildCount() == 1 &&
where_to_add->getInt() == kSubFolder)
{
InfoMap imageMap;
metadata->GetImageMap(imageMap);
where_to_add->SetImageFromMap(imageMap);
where_to_add->SetImage("buttonimage", imageMap["smartimage"]);
}

// Statetypes
InfoMap stateMap;
metadata->GetStateMap(stateMap);
sub_node->DisplayStateFromMap(stateMap);

return 1;
}

Expand Down