Skip to content

Commit

Permalink
Moved parsing of screenshot-template to mpvhandler
Browse files Browse the repository at this point in the history
It started to show up all over the place so I consolidated it into mpvhandler on loading settings. The only place it's repeated is in preferences dialog which should be modified to not write directly to settings as it is now.

Fixed up the screenshot message.
  • Loading branch information
u8sand committed Nov 20, 2014
1 parent 42446a7 commit 3b4a2fb
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 47 deletions.
39 changes: 28 additions & 11 deletions src/mpvhandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,20 @@ void MpvHandler::LoadSettings(QSettings *settings, QString version)
else if(parts[1] == "speed")
Speed(settings->value(key).toDouble());
else if(parts[1] == "screenshot-template")
ScreenshotTemplate(settings->value(key).toString());
{
QString temp = settings->value(key).toString();
int i = temp.lastIndexOf('/');
if(i != -1)
{
ScreenshotDirectory(temp.mid(0, i));
ScreenshotTemplate(temp.mid(i+1));
}
else
{
ScreenshotDirectory(".");
ScreenshotTemplate(temp);
}
}
else
{
QByteArray tmp1 = parts[1].toUtf8(),
Expand All @@ -167,14 +180,8 @@ void MpvHandler::LoadSettings(QSettings *settings, QString version)
else
setLastFile("");
ScreenshotFormat(settings->value("mpv/screenshotFormat", "jpg").toString());
QString dir = settings->value("mpv/screenshotDir", "").toString(),
temp = settings->value("mpv/screenshotTemplate", "").toString();
if(dir != "" && temp != "")
ScreenshotTemplate(dir+"/"+temp);
else if(dir != "")
ScreenshotTemplate(dir+"/screenshot%#04n");
else if(temp != "")
ScreenshotTemplate(temp);
ScreenshotDirectory(settings->value("mpv/screenshotDir", ".").toString());
ScreenshotTemplate(settings->value("mpv/screenshotTemplate", "screenshot%#04n").toString());
Speed(settings->value("mpv/speed", 1.0).toDouble());
Volume(settings->value("mpv/volume", 100).toInt());
Debug(settings->value("common/debug", false).toBool());
Expand Down Expand Up @@ -215,7 +222,7 @@ void MpvHandler::SaveSettings(QSettings *settings)
if(screenshotFormat != "")
settings->setValue("mpv/screenshot-format", screenshotFormat);
if(screenshotTemplate != "")
settings->setValue("mpv/screenshot-template", screenshotTemplate);
settings->setValue("mpv/screenshot-template", screenshotDir+"/"+screenshotTemplate);
}
}

Expand Down Expand Up @@ -457,12 +464,22 @@ void MpvHandler::ScreenshotTemplate(QString s)
{
if(mpv)
{
const QByteArray tmp = s.toUtf8();
const QByteArray tmp = (screenshotDir+"/"+s).toUtf8();
mpv_set_option_string(mpv, "screenshot-template", tmp.data());
}
setScreenshotTemplate(s);
}

void MpvHandler::ScreenshotDirectory(QString s)
{
// if(mpv)
// {
// const QByteArray tmp = (s+"/"+screenshotTemplate).toUtf8();
// mpv_set_option_string(mpv, "screenshot-template", tmp.data());
// }
setScreenshotDir(s);
}

void MpvHandler::AddSubtitleTrack(QString f)
{
const QByteArray tmp = f.toUtf8();
Expand Down
5 changes: 5 additions & 0 deletions src/mpvhandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class MpvHandler : public QObject
QString getLastFile() { return lastFile; }
QString getScreenshotFormat() { return screenshotFormat; }
QString getScreenshotTemplate() { return screenshotTemplate; }
QString getScreenshotDir() { return screenshotDir; }
double getSpeed() { return speed; }
int getTime() { return time; }
int getVolume() { return volume; }
Expand Down Expand Up @@ -73,6 +74,7 @@ public slots:

void ScreenshotFormat(QString);
void ScreenshotTemplate(QString);
void ScreenshotDirectory(QString);

void AddSubtitleTrack(QString);
void ShowSubtitles(bool);
Expand Down Expand Up @@ -103,6 +105,7 @@ private slots:
void setLastFile(QString s) { emit lastFileChanged(lastFile = s); }
void setScreenshotFormat(QString s) { emit screenshotFormatChanged(screenshotFormat = s); }
void setScreenshotTemplate(QString s) { emit screenshotTemplateChanged(screenshotTemplate = s); }
void setScreenshotDir(QString s) { emit screenshotDirChanged(screenshotDir = s); }
void setSpeed(double d) { emit speedChanged(speed = d); }
void setTime(int i) { emit timeChanged(time = i); }
void setVolume(int i) { emit volumeChanged(volume = i); }
Expand All @@ -126,6 +129,7 @@ private slots:
void lastFileChanged(QString);
void screenshotFormatChanged(QString);
void screenshotTemplateChanged(QString);
void screenshotDirChanged(QString);
void speedChanged(double);
void timeChanged(int);
void volumeChanged(int);
Expand Down Expand Up @@ -156,6 +160,7 @@ private slots:
lastFile,
screenshotFormat,
screenshotTemplate,
screenshotDir,
suffix;
double speed = 1;
int time = 0,
Expand Down
16 changes: 3 additions & 13 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1668,7 +1668,8 @@ void MainWindow::TakeScreenshot(bool subs)
if(screenshotDialog)
{
mpv->Pause();
subs = ScreenshotDialog::showScreenshotDialog(screenshotDialog, subs, mpv);
if(ScreenshotDialog::showScreenshotDialog(screenshotDialog, subs, mpv) != QDialog::Accepted)
return;
}
else
mpv->Screenshot(subs);
Expand All @@ -1677,20 +1678,9 @@ void MainWindow::TakeScreenshot(bool subs)

void MainWindow::ShowScreenshotMessage(bool subs)
{
QString dir = mpv->getScreenshotTemplate();
QString dir = mpv->getScreenshotDir();
int i = dir.lastIndexOf('/');
if(i != -1)
{
dir.truncate(i);
i = dir.lastIndexOf('/');
if(i != -1)
dir.remove(0, i+1);
}
else
{
dir = QApplication::applicationDirPath();
i = dir.lastIndexOf('/');
dir.remove(0, i+1);
}
mpv->ShowText("Saved to \""+dir+"\", "+(subs?"with":"without")+" subs");
}
30 changes: 11 additions & 19 deletions src/ui/screenshotdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include <QFileDialog>
#include <QString>

ScreenshotDialog::ScreenshotDialog(bool &_always, bool screenshot, MpvHandler *mpv, QWidget *parent) :
ScreenshotDialog::ScreenshotDialog(bool &_always, bool &_screenshot, MpvHandler *mpv, QWidget *parent) :
QDialog(parent),
ui(new Ui::ScreenshotDialog),
always(_always)
always(_always),
screenshot(_screenshot)
{
ui->setupUi(this);

Expand All @@ -16,18 +17,8 @@ ScreenshotDialog::ScreenshotDialog(bool &_always, bool screenshot, MpvHandler *m
ui->templateEdit->setText(mpv->getScreenshotTemplate());
ui->formatComboBox->setCurrentText(mpv->getScreenshotFormat());

QString screenshotTemplate = mpv->getScreenshotTemplate();
int i = screenshotTemplate.lastIndexOf('/');
if(i != -1)
{
ui->locationEdit->setText(screenshotTemplate.mid(0, i));
ui->templateEdit->setText(screenshotTemplate.mid(i+1));
}
else
{
ui->templateEdit->setText(screenshotTemplate);
ui->locationEdit->setText(".");
}
ui->locationEdit->setText(mpv->getScreenshotDir());
ui->templateEdit->setText(mpv->getScreenshotTemplate());

connect(ui->browseButton, &QPushButton::clicked,
[=]
Expand All @@ -41,9 +32,11 @@ ScreenshotDialog::ScreenshotDialog(bool &_always, bool screenshot, MpvHandler *m
[=]
{
mpv->ScreenshotFormat(ui->formatComboBox->currentText());
mpv->ScreenshotTemplate(ui->locationEdit->text()+"/"+ui->templateEdit->text());
mpv->ScreenshotDirectory(ui->locationEdit->text());
mpv->ScreenshotTemplate(ui->templateEdit->text());
always = ui->showCheckBox->isChecked();
mpv->Screenshot(ui->subtitlesCheckBox->isChecked());
screenshot = ui->subtitlesCheckBox->isChecked();
mpv->Screenshot(screenshot);
accept();
});
}
Expand All @@ -53,9 +46,8 @@ ScreenshotDialog::~ScreenshotDialog()
delete ui;
}

bool ScreenshotDialog::showScreenshotDialog(bool &always, bool screenshot, MpvHandler *mpv, QWidget *parent)
int ScreenshotDialog::showScreenshotDialog(bool &always, bool &screenshot, MpvHandler *mpv, QWidget *parent)
{
ScreenshotDialog dialog(always, screenshot, mpv, parent);
dialog.exec();
return dialog.ui->subtitlesCheckBox->isChecked();
return dialog.exec();
}
9 changes: 5 additions & 4 deletions src/ui/screenshotdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ class ScreenshotDialog : public QDialog
{
Q_OBJECT

public://ScreenshotDialog::showDialog(screenshotDialog, true, mpv);
explicit ScreenshotDialog(bool &always, bool screenshot, MpvHandler *mpv, QWidget *parent = 0);
public:
explicit ScreenshotDialog(bool &always, bool &screenshot, MpvHandler *mpv, QWidget *parent = 0);
~ScreenshotDialog();

static bool showScreenshotDialog(bool &always, bool screenshot, MpvHandler *mpv, QWidget *parent = 0);
static int showScreenshotDialog(bool &always, bool &screenshot, MpvHandler *mpv, QWidget *parent = 0);
private:
Ui::ScreenshotDialog *ui;
bool &always;
bool &always,
&screenshot;
};

#endif // SCREENSHOTDIALOG_H

0 comments on commit 3b4a2fb

Please sign in to comment.