Skip to content

Commit

Permalink
MythVideo: Fix the remember position setting.
Browse files Browse the repository at this point in the history
This fixes the setting to restore the same position in browser, gallery and
tree views when returning to MythVideo or when switching views. Fixes #7425.
  • Loading branch information
Paul Harrison committed Jun 26, 2011
1 parent febf85c commit b03a6b6
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 10 deletions.
85 changes: 75 additions & 10 deletions mythtv/programs/mythfrontend/videodlg.cpp
Expand Up @@ -1026,9 +1026,35 @@ VideoDialog::~VideoDialog()
if (!m_d->m_switchingLayout)
m_d->DelayVideoListDestruction(m_d->m_videoList);

SavePosition();

delete m_d;
}

void VideoDialog::SavePosition(void)
{
m_d->m_lastTreeNodePath = "";

if (m_d->m_type == DLG_TREE)
{
MythGenericTree *node = m_videoButtonTree->GetCurrentNode();
if (node)
m_d->m_lastTreeNodePath = node->getRouteByString().join("\n");
}
else if (m_d->m_type == DLG_BROWSER || m_d->m_type == DLG_GALLERY)
{
MythUIButtonListItem *item = m_videoButtonList->GetItemCurrent();
if (item)
{
MythGenericTree *node = GetNodePtrFromButton(item);
if (node)
m_d->m_lastTreeNodePath = node->getRouteByString().join("\n");
}
}

gCoreContext->SaveSetting("mythvideo.VideoTreeLastActive", m_d->m_lastTreeNodePath);
}

bool VideoDialog::Create()
{
if (m_d->m_type == DLG_DEFAULT)
Expand Down Expand Up @@ -1234,6 +1260,7 @@ void VideoDialog::loadData()
if (m_d->m_type == DLG_TREE)
{
m_videoButtonTree->AssignTree(m_d->m_rootNode);

if (m_d->m_firstLoadPass)
{
m_d->m_firstLoadPass = false;
Expand Down Expand Up @@ -1262,6 +1289,52 @@ void VideoDialog::loadData()

MythGenericTree *selectedNode = m_d->m_currentNode->getSelectedChild();

// restore the last saved position in the video tree if this is the first
// time this method is called and the option is set in the database
if (m_d->m_firstLoadPass)
{
if (m_d->m_rememberPosition)
{
QStringList lastTreeNodePath = gCoreContext->GetSetting("mythvideo.VideoTreeLastActive", "").split("\n");

if (m_d->m_type == DLG_GALLERY || m_d->m_type == DLG_BROWSER)
{
if (lastTreeNodePath.size() > 0)
{
MythGenericTree *node;

// go through the path list and set the current node
for (int i = 0; i < lastTreeNodePath.size(); i++)
{
node = m_d->m_currentNode->getChildByName(lastTreeNodePath.at(i));
if (node != NULL)
{
// check if the node name is the same as the currently selected
// one in the saved tree list. if yes then we are on the right
// way down the video tree to find the last saved position
if (node->getString().compare(lastTreeNodePath.at(i)) == 0)
{
// set the folder as the new node so we can travel further down
// dont do this if its the last part of the saved video path tree
if (node->getInt() == kSubFolder &&
node->childCount() > 1 &&
i < lastTreeNodePath.size()-1)
{
SetCurrentNode(node);
}
// in the last run the selectedNode will be the last
// entry of the saved tree node.
if (lastTreeNodePath.at(i) == lastTreeNodePath.last())
selectedNode = node;
}
}
}
m_d->m_firstLoadPass = false;
}
}
}
}

typedef QList<MythGenericTree *> MGTreeChildList;
MGTreeChildList *lchildren = m_d->m_currentNode->getAllChildren();

Expand Down Expand Up @@ -2381,8 +2454,6 @@ void VideoDialog::UpdateText(MythUIButtonListItem *item)
CheckedSet(this, "foldername", m_d->m_currentNode->getString());
}



if (node && node->getInt() == kSubFolder)
CheckedSet(this, "childcount",
QString("%1").arg(node->visibleChildCount()));
Expand Down Expand Up @@ -2947,14 +3018,8 @@ void VideoDialog::SwitchLayout(DialogType type, BrowseType browse)
{
m_d->m_switchingLayout = true;

if (m_d->m_rememberPosition && m_videoButtonTree)
{
MythGenericTree *node = m_videoButtonTree->GetCurrentNode();
if (node)
{
m_d->m_lastTreeNodePath = node->getRouteByString().join("\n");
}
}
// save current position so it can be restored after the switch
SavePosition();

VideoDialog *mythvideo =
new VideoDialog(GetMythMainWindow()->GetMainStack(), "mythvideo",
Expand Down
2 changes: 2 additions & 0 deletions mythtv/programs/mythfrontend/videodlg.h
Expand Up @@ -172,6 +172,8 @@ class VideoDialog : public MythScreenType
QStringList fanart = QStringList(), QStringList banner = QStringList(),
QStringList screenshot = QStringList());

void SavePosition(void);

private slots:

void OnVideoImageSetDone(VideoMetadata *metadata);
Expand Down
11 changes: 11 additions & 0 deletions mythtv/programs/mythfrontend/videoglobalsettings.cpp
Expand Up @@ -172,6 +172,16 @@ HostSlider *SetDVDDriveSpeed()
return gs;
}

HostCheckBox *VideoTreeRemember()
{
HostCheckBox *gc = new HostCheckBox("mythvideo.VideoTreeRemember");
gc->setLabel(QObject::tr("Video Tree remembers last selected position"));
gc->setValue(false);
gc->setHelpText(QObject::tr("If set, the current position in the Video "
"Tree is persistent."));
return gc;
}

struct ConfigPage
{
typedef std::vector<ConfigurationGroup *> PageList;
Expand Down Expand Up @@ -286,6 +296,7 @@ VideoGeneralSettings::VideoGeneralSettings()
VConfigPage page2(pages, false);
page2->addChild(SetOnInsertDVD());
page2->addChild(SetDVDDriveSpeed());
page2->addChild(VideoTreeRemember());

// page 3
VerticalConfigurationGroup *pctrl =
Expand Down

0 comments on commit b03a6b6

Please sign in to comment.