Skip to content

Commit

Permalink
Refactor to QSharedPointer for AutoSaveFile.
Browse files Browse the repository at this point in the history
  • Loading branch information
ddennedy committed Jun 17, 2016
1 parent 4a0e183 commit 36aa34b
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 23 deletions.
27 changes: 6 additions & 21 deletions src/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ MainWindow::MainWindow()
, m_keyerMenu(0)
, m_isPlaylistLoaded(false)
, m_htmlEditor(0)
, m_autosaveFile(0)
, m_exitCode(EXIT_SUCCESS)
, m_navigationPosition(0)
{
Expand Down Expand Up @@ -494,11 +493,6 @@ MainWindow& MainWindow::singleton()

MainWindow::~MainWindow()
{
m_autosaveMutex.lock();
delete m_autosaveFile;
m_autosaveFile = 0;
m_autosaveMutex.unlock();

delete m_htmlEditor;
delete ui;
Mlt::Controller::destroy();
Expand Down Expand Up @@ -915,7 +909,7 @@ bool MainWindow::checkAutoSave(QString &url)
QMutexLocker locker(&m_autosaveMutex);

// check whether autosave files exist:
AutoSaveFile* stale = AutoSaveFile::getFile(url);
QSharedPointer<AutoSaveFile> stale(AutoSaveFile::getFile(url));
if (stale) {
QMessageBox dialog(QMessageBox::Question, qApp->applicationName(),
tr("Auto-saved files exist. Do you want to recover them now?"),
Expand All @@ -927,22 +921,16 @@ bool MainWindow::checkAutoSave(QString &url)
if (r == QMessageBox::Yes) {
if (!stale->open(QIODevice::ReadWrite)) {
LOG_WARNING() << "failed to recover autosave file" << url;
delete stale;
} else {
delete m_autosaveFile;
m_autosaveFile = stale;
url = stale->fileName();
return true;
}
} else {
// remove the stale file
delete stale;
}
}

// create new autosave object
delete m_autosaveFile;
m_autosaveFile = new AutoSaveFile(url);
m_autosaveFile.reset(new AutoSaveFile(url));

return false;
}
Expand All @@ -954,15 +942,14 @@ void MainWindow::stepLeftBySeconds(int sec)

void MainWindow::doAutosave()
{
m_autosaveMutex.lock();
QMutexLocker locker(&m_autosaveMutex);
if (m_autosaveFile) {
if (m_autosaveFile->isOpen() || m_autosaveFile->open(QIODevice::ReadWrite)) {
saveXML(m_autosaveFile->fileName(), false /* without relative paths */);
} else {
LOG_ERROR() << "failed to open autosave file for writing" << m_autosaveFile->fileName();
}
}
m_autosaveMutex.unlock();
}

void MainWindow::setFullScreen(bool isFullScreen)
Expand Down Expand Up @@ -1943,7 +1930,7 @@ bool MainWindow::on_actionSave_As_triggered()
if (m_autosaveFile)
m_autosaveFile->changeManagedFile(filename);
else
m_autosaveFile = new AutoSaveFile(filename);
m_autosaveFile.reset(new AutoSaveFile(filename));
setCurrentFile(filename);
setWindowModified(false);
if (MLT.producer())
Expand Down Expand Up @@ -2101,8 +2088,7 @@ void MainWindow::onPlaylistClosed()
setWindowModified(false);
m_undoStack->clear();
MLT.resetURL();
delete m_autosaveFile;
m_autosaveFile = new AutoSaveFile(untitledFileName());
m_autosaveFile.reset(new AutoSaveFile(untitledFileName()));
if (!multitrack())
m_player->enableTab(Player::ProjectTabIndex, false);
}
Expand All @@ -2129,8 +2115,7 @@ void MainWindow::onMultitrackClosed()
setWindowModified(false);
m_undoStack->clear();
MLT.resetURL();
delete m_autosaveFile;
m_autosaveFile = new AutoSaveFile(untitledFileName());
m_autosaveFile.reset(new AutoSaveFile(untitledFileName()));
if (!playlist() || playlist()->count() == 0)
m_player->enableTab(Player::ProjectTabIndex, false);
}
Expand Down
6 changes: 4 additions & 2 deletions src/mainwindow.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2011-2015 Meltytech, LLC
* Copyright (c) 2011-2016 Meltytech, LLC
* Author: Dan Dennedy <dan@dennedy.org>
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -24,6 +24,8 @@
#include <QTimer>
#include <QUrl>
#include <QNetworkAccessManager>
#include <QScopedPointer>
#include <QSharedPointer>
#include "mltcontroller.h"
#include "mltxmlchecker.h"

Expand Down Expand Up @@ -132,7 +134,7 @@ class MainWindow : public QMainWindow
bool m_isPlaylistLoaded;
QActionGroup* m_languagesGroup;
HtmlEditor* m_htmlEditor;
AutoSaveFile* m_autosaveFile;
QSharedPointer<AutoSaveFile> m_autosaveFile;
QMutex m_autosaveMutex;
QTimer m_autosaveTimer;
int m_exitCode;
Expand Down

0 comments on commit 36aa34b

Please sign in to comment.