Skip to content

Commit

Permalink
Merge pull request #260 from mikfire/bugs/dbbackup
Browse files Browse the repository at this point in the history
Fixes #247 -- Database vanished
  • Loading branch information
mikfire committed Jun 3, 2016
2 parents 6cb5a50 + 7f060cf commit ef633e3
Show file tree
Hide file tree
Showing 10 changed files with 535 additions and 592 deletions.
43 changes: 7 additions & 36 deletions src/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,9 @@ MainWindow::MainWindow(QWidget* parent)

QDesktopWidget *desktop = QApplication::desktop();

// Ensure database initializes.
Database::instance();
// If the database doesn't load, we bail
if (! Database::instance().loadSuccessful() )
exit(1);

// Set the window title.
setWindowTitle( QString("Brewtarget - %1").arg(VERSIONSTRING) );
Expand Down Expand Up @@ -421,13 +422,11 @@ MainWindow::MainWindow(QWidget* parent)
if ( Brewtarget::dbType() == Brewtarget::PGSQL ) {
actionBackup_Database->setEnabled(false);
actionRestore_Database->setEnabled(false);
actionSave->setEnabled(false);
label_Brewtarget->setToolTip( recipeFormatter->getLabelToolTip());
}
else {
connect( actionBackup_Database, SIGNAL( triggered() ), this, SLOT( backup() ) );
connect( actionRestore_Database, SIGNAL( triggered() ), this, SLOT( restoreFromBackup() ) );
connect( actionSave, SIGNAL(triggered()), this, SLOT(save()) );
}
// Printing signals/slots.
// Refactoring is good. It's like a rye saison fermenting away
Expand Down Expand Up @@ -496,14 +495,12 @@ MainWindow::MainWindow(QWidget* parent)
// No connections from the database yet? Oh FSM, that probably means I'm
// doing it wrong again.
connect( &(Database::instance()), SIGNAL( deletedSignal(BrewNote*)), this, SLOT( closeBrewNote(BrewNote*)));
connect( &(Database::instance()), SIGNAL( isUnsavedChanged(bool)), this, SLOT( updateUnsavedStatus(bool)));
}

void MainWindow::setupShortCuts()
{
actionNewRecipe->setShortcut(QKeySequence::New);
actionCopy_Recipe->setShortcut(QKeySequence::Copy);
actionSave->setShortcut(QKeySequence::Save);
actionDeleteSelected->setShortcut(QKeySequence::Delete);
}

Expand Down Expand Up @@ -1909,11 +1906,6 @@ void MainWindow::removeMash()

}

void MainWindow::save()
{
Database::instance().saveDatabase();
}

void MainWindow::closeEvent(QCloseEvent* /*event*/)
{
Brewtarget::saveSystemOptions();
Expand Down Expand Up @@ -1941,20 +1933,10 @@ void MainWindow::closeEvent(QCloseEvent* /*event*/)

// Ask the user if they want to save changes, only if the dirty bit has
// been thrown
if( Database::instance().isDirty() &&
QMessageBox::question(this,
QObject::tr("Save Database Changes"),
QObject::tr("Would you like to save the changes you made?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::Yes)
== QMessageBox::Yes)
{
Database::instance().unload(true);
}
else
{
Database::instance().unload(false);
}
// We should also make sure the backup db still exists -- there's some edge
// cases where it doesn't.

Database::instance().unload();
}

void MainWindow::copyRecipe()
Expand Down Expand Up @@ -2450,17 +2432,6 @@ void MainWindow::updateStatus(const QString status) {
statusBar()->showMessage(status, 3000);
}

void MainWindow::updateUnsavedStatus(bool isUnsaved) {
if ( isUnsaved ) {
statusBar()->showMessage(tr("Unsaved Changes"));
actionSave->setIcon(QIcon(SAVEDIRTYPNG));
}
else {
statusBar()->clearMessage();
actionSave->setIcon(QIcon(SAVEPNG));
}
}

void MainWindow::closeBrewNote(BrewNote* b)
{
Recipe* parent = Database::instance().getParentRecipe(b);
Expand Down
5 changes: 0 additions & 5 deletions src/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,8 +144,6 @@ public slots:

//! \brief Update the main windows statusbar.
void updateStatus(const QString status);
//! \brief Change unsaved status.
void updateUnsavedStatus(bool isUnsaved);

//! \brief Close a brewnote tab if we must
void closeBrewNote(BrewNote*);
Expand Down Expand Up @@ -218,9 +216,6 @@ public slots:

//! \brief Prints the right thing, depending on the signal sender.
void print();
//! \brief saves the database, which will have some interesting
//implications later
void save();
//! \brief Backup the database.
void backup();
//! \brief Restore the database.
Expand Down
Loading

0 comments on commit ef633e3

Please sign in to comment.