Skip to content

Commit

Permalink
Adjusted lastFile functionality a bit
Browse files Browse the repository at this point in the history
The recent will only update if the next files is not the same as the current (to remove redundancy) and also the UI is updated before changing the internal; this way recent only shows what was there (without the CURRENT file in the first spot)
  • Loading branch information
u8sand committed Nov 26, 2014
1 parent b8b81d3 commit 4f793aa
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 41 deletions.
8 changes: 3 additions & 5 deletions etc/doc/baka-mplayer.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Clicking the Index allows you to type a specific index to play--this is particul
Screenshots are taken through mpv. The template specified is passed into mpv as screenshot-template; see mpv's manual for more details on valid screenshot-template. Specified directories are prepended to the screenshot-template. If the screenshot dialog is hidden by unchecking the `Always show this dialog` option, the dialog can be restored by setting `baka-mplayer/screenshotDialog` to true in the settings file.

### Recent Files
Your recently viewed files are stored in settings for easy access. They will be seen in the settings file at the bottom as `recent/files`. To make the recent history bigger or smaller simply set `recent/max` and the list will trim itself accordingly.
Your recently viewed files are stored in settings for easy access. They will be seen in the settings file at the bottom as `baka-mplayer/recent`. To make the recent history bigger or smaller simply set `baka-mplayer/maxRecent` and the list will trim itself accordingly.

### Special functions
Some functionality is not entirely explained to the user; this is explained here.
Expand Down Expand Up @@ -64,7 +64,9 @@ On Linux, they are saved in the Qt location `~/.config/bakamplayer.ini`.
debug= # debugging enabled (output box)
height= # height of the window
hidePopup= # hide tray icon notifications
maxRecent= # the maximum files saved in recent
onTop= # on top setting (always, never, or playing)
recent= # recent file history
remaining= # display remaining time or duration time label
screenshotDialog= # always show the screenshot dialog when taking screenshots
showAll= # Should we load files of different extensions
Expand All @@ -79,9 +81,5 @@ On Linux, they are saved in the Qt location `~/.config/bakamplayer.ini`.
af= # audio filters
volume= # volume
# ...
[recent] # recent file history
files= # the files
max= # the maximum files saved in recent

Note that for mpv specific options you can use mpv's options. See mpv's manual for valid options.
67 changes: 33 additions & 34 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,32 +82,6 @@ MainWindow::MainWindow(QWidget *parent):
// setup signals & slots

// mainwindow
connect(this, &MainWindow::recentChanged,
[=](QStringList &r)
{
ui->menu_Recently_Opened->clear();
QAction *action;
int n = 1,
N = r.length();
bool last = false;
for(auto &f : r)
{
action = ui->menu_Recently_Opened->addAction(FormatNumberWithAmpersand(n++, N)+
". "+
ShortenPathToParent(f).replace("&","&&"));
if(!last && f != mpv->getPath()+mpv->getFile())
{
action->setShortcut(QKeySequence("Ctrl+Z"));
last = true;
}
connect(action, &QAction::triggered,
[=]
{
mpv->LoadFile(f);
});
}
});

connect(this, &MainWindow::onTopChanged,
[=](QString onTop)
{
Expand Down Expand Up @@ -449,13 +423,17 @@ MainWindow::MainWindow(QWidget *parent):
firstItem = false;
}

if(f != QString() && maxRecent > 0)
QString file = mpv->getPath()+f;
if(init &&
recent.front() != file &&
f != QString() &&
maxRecent > 0)
{
recent.removeAll(mpv->getPath()+f);
UpdateRecentFiles(); // update after initialization and only if the current file is different from the first recent
recent.removeAll(file);
while(recent.length() > maxRecent-1)
recent.removeLast();
recent.push_front(mpv->getPath()+f);
emit recentChanged(recent);
recent.push_front(file);
}
});

Expand Down Expand Up @@ -1240,9 +1218,9 @@ void MainWindow::LoadSettings()
ui->hideFilesButton->setChecked(!settings->value("showAll", true).toBool());
setScreenshotDialog(settings->value("screenshotDialog", true).toBool());
recent = settings->value("recent").toStringList();
emit recentChanged(recent);
maxRecent = settings->value("maxRecent", 5).toInt();
settings->endGroup();
UpdateRecentFiles();

mpv->LoadSettings(settings, version);
}
Expand All @@ -1262,8 +1240,8 @@ void MainWindow::LoadSettings()
QString lf = settings->value("lastFile").toString();
if(lf != QString())
recent.push_front(lf);
emit recentChanged(recent);
settings->endGroup();
UpdateRecentFiles();

mpv->LoadSettings(settings, version);

Expand Down Expand Up @@ -1292,7 +1270,7 @@ void MainWindow::LoadSettings()
QString lf = settings->value("mpv/lastFile").toString();
if(lf != QString())
recent.push_front(lf);
emit recentChanged(recent);
UpdateRecentFiles();

mpv->LoadSettings(settings, version);

Expand All @@ -1314,9 +1292,9 @@ void MainWindow::LoadSettings()
ui->hideFilesButton->setChecked(!settings->value("showAll", true).toBool());
setScreenshotDialog(settings->value("screenshotDialog", true).toBool());
recent = settings->value("recent").toStringList();
emit recentChanged(recent);
maxRecent = settings->value("maxRecent", 5).toInt();
settings->endGroup();
UpdateRecentFiles();

mpv->LoadSettings(settings, version);

Expand Down Expand Up @@ -1738,3 +1716,24 @@ void MainWindow::ShowScreenshotMessage(bool subs)
dir.remove(0, i+1);
mpv->ShowText("Saved to \""+dir+"\", "+(subs?"with":"without")+" subs");
}

void MainWindow::UpdateRecentFiles()
{
ui->menu_Recently_Opened->clear();
QAction *action;
int n = 1,
N = recent.length();
for(auto &f : recent)
{
action = ui->menu_Recently_Opened->addAction(FormatNumberWithAmpersand(n, N)+
". "+
ShortenPathToParent(f).replace("&","&&"));
if(n++ == 1)
action->setShortcut(QKeySequence("Ctrl+Z"));
connect(action, &QAction::triggered,
[=]
{
mpv->LoadFile(f);
});
}
}
3 changes: 1 addition & 2 deletions src/ui/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ private slots:
void AlwaysOnTop(bool ontop); // set always on top window state
void TakeScreenshot(bool subs); // take a screenshot
void ShowScreenshotMessage(bool subs); // show the screenshot status message
void UpdateRecentFiles(); // populate recentFiles menu

private:
Ui::MainWindow *ui;
Expand Down Expand Up @@ -85,7 +86,6 @@ private slots:
debug;

public slots:
void setRecent(QStringList s) { recent = s; emit recentChanged(recent); }
void setOnTop(QString s) { emit onTopChanged(onTop = s); }
void setAutoFit(int b) { emit autoFitChanged(autoFit = b); }
void setHidePopup(bool b) { emit hidePopupChanged(hidePopup = b); }
Expand All @@ -94,7 +94,6 @@ public slots:
void setDebug(bool b) { emit debugChanged(debug = b); }

signals:
void recentChanged(QStringList&);
void onTopChanged(QString);
void autoFitChanged(int);
void hidePopupChanged(bool);
Expand Down

0 comments on commit 4f793aa

Please sign in to comment.