2010-09-19 10:59:32 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2010 Felix Geyer <debfx@fobos.de>
|
|
|
|
*
|
|
|
|
* This program is free software: you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation, either version 2 or (at your option)
|
|
|
|
* version 3 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "MainWindow.h"
|
2011-12-26 12:55:50 -05:00
|
|
|
#include "ui_MainWindow.h"
|
2010-09-19 10:59:32 -04:00
|
|
|
|
2012-04-11 14:35:52 -04:00
|
|
|
#include <QtGui/QCloseEvent>
|
|
|
|
|
2010-09-19 10:59:32 -04:00
|
|
|
#include "core/Database.h"
|
2012-01-05 16:27:08 -05:00
|
|
|
#include "core/DataPath.h"
|
2010-09-19 10:59:32 -04:00
|
|
|
#include "core/Metadata.h"
|
2011-07-08 08:51:14 -04:00
|
|
|
#include "gui/DatabaseWidget.h"
|
2012-04-16 15:28:49 -04:00
|
|
|
#include "gui/EntryView.h"
|
2010-09-19 10:59:32 -04:00
|
|
|
|
|
|
|
MainWindow::MainWindow()
|
2011-12-26 12:55:50 -05:00
|
|
|
: m_ui(new Ui::MainWindow())
|
2010-09-19 10:59:32 -04:00
|
|
|
{
|
2011-12-26 12:55:50 -05:00
|
|
|
m_ui->setupUi(this);
|
2010-09-19 10:59:32 -04:00
|
|
|
|
2012-01-05 16:36:06 -05:00
|
|
|
setWindowIcon(dataPath()->applicationIcon());
|
2012-01-05 16:27:08 -05:00
|
|
|
|
2012-04-16 15:28:49 -04:00
|
|
|
connect(m_ui->tabWidget, SIGNAL(entrySelectionChanged(bool)), SLOT(setMenuActionState()));
|
|
|
|
connect(m_ui->tabWidget, SIGNAL(currentWidgetIndexChanged(int)), SLOT(setMenuActionState(int)));
|
2011-12-30 12:43:24 -05:00
|
|
|
|
|
|
|
connect(m_ui->actionDatabaseNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(newDatabase()));
|
|
|
|
connect(m_ui->actionDatabaseOpen, SIGNAL(triggered()), m_ui->tabWidget, SLOT(openDatabase()));
|
|
|
|
connect(m_ui->actionDatabaseSave, SIGNAL(triggered()), m_ui->tabWidget, SLOT(saveDatabase()));
|
|
|
|
connect(m_ui->actionDatabaseSaveAs, SIGNAL(triggered()), m_ui->tabWidget, SLOT(saveDatabaseAs()));
|
|
|
|
connect(m_ui->actionDatabaseClose, SIGNAL(triggered()), m_ui->tabWidget, SLOT(closeDatabase()));
|
2012-01-13 11:52:37 -05:00
|
|
|
connect(m_ui->actionChangeMasterKey, SIGNAL(triggered()), m_ui->tabWidget, SLOT(changeMasterKey()));
|
2012-04-19 10:20:20 -04:00
|
|
|
connect(m_ui->actionChangeDatabaseSettings, SIGNAL(triggered()), m_ui->tabWidget, SLOT(changeDatabaseSettings()));
|
2011-12-30 12:43:24 -05:00
|
|
|
connect(m_ui->actionEntryNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(createEntry()));
|
|
|
|
connect(m_ui->actionEntryEdit, SIGNAL(triggered()), m_ui->tabWidget, SLOT(editEntry()));
|
2012-04-18 14:08:54 -04:00
|
|
|
connect(m_ui->actionEntryDelete, SIGNAL(triggered()), m_ui->tabWidget, SLOT(deleteEntry()));
|
2011-12-30 12:43:24 -05:00
|
|
|
connect(m_ui->actionGroupNew, SIGNAL(triggered()), m_ui->tabWidget, SLOT(createGroup()));
|
|
|
|
connect(m_ui->actionGroupEdit, SIGNAL(triggered()), m_ui->tabWidget, SLOT(editGroup()));
|
2012-04-21 13:06:28 -04:00
|
|
|
connect(m_ui->actionGroupDelete, SIGNAL(triggered()), m_ui->tabWidget, SLOT(deleteGroup()));
|
2011-12-26 12:55:50 -05:00
|
|
|
connect(m_ui->actionQuit, SIGNAL(triggered()), SLOT(close()));
|
|
|
|
}
|
|
|
|
|
|
|
|
MainWindow::~MainWindow()
|
|
|
|
{
|
2010-09-19 10:59:32 -04:00
|
|
|
}
|
2011-11-16 12:47:17 -05:00
|
|
|
|
2012-04-16 15:28:49 -04:00
|
|
|
void MainWindow::setMenuActionState(int index)
|
2011-11-16 12:47:17 -05:00
|
|
|
{
|
2012-04-18 18:25:57 -04:00
|
|
|
if (m_ui->tabWidget->currentIndex() != -1) {
|
2012-04-16 15:28:49 -04:00
|
|
|
m_ui->actionDatabaseClose->setEnabled(true);
|
|
|
|
DatabaseWidget* dbWidget = m_ui->tabWidget->currentDatabaseWidget();
|
|
|
|
Q_ASSERT(dbWidget);
|
|
|
|
|
|
|
|
if (index == -1) {
|
|
|
|
index = dbWidget->currentIndex();
|
|
|
|
}
|
|
|
|
|
2012-04-18 16:08:22 -04:00
|
|
|
switch (index) {
|
2012-04-16 15:28:49 -04:00
|
|
|
case 0: // view
|
|
|
|
m_ui->actionEntryNew->setEnabled(true);
|
|
|
|
m_ui->actionGroupNew->setEnabled(true);
|
|
|
|
if (dbWidget->entryView()->currentIndex().isValid()) {
|
|
|
|
m_ui->actionEntryEdit->setEnabled(true);
|
|
|
|
m_ui->actionEntryDelete->setEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_ui->actionEntryEdit->setEnabled(false);
|
|
|
|
m_ui->actionEntryDelete->setEnabled(false);
|
|
|
|
}
|
|
|
|
m_ui->actionGroupEdit->setEnabled(true);
|
2012-04-21 13:06:28 -04:00
|
|
|
|
|
|
|
if (dbWidget->canDeleteCurrentGoup()) {
|
|
|
|
m_ui->actionGroupDelete->setEnabled(true);
|
2012-04-16 15:28:49 -04:00
|
|
|
}
|
|
|
|
else {
|
2012-04-21 13:06:28 -04:00
|
|
|
m_ui->actionGroupDelete->setEnabled(false);
|
2012-04-16 15:28:49 -04:00
|
|
|
}
|
|
|
|
m_ui->actionChangeMasterKey->setEnabled(true);
|
2012-04-19 10:20:20 -04:00
|
|
|
m_ui->actionChangeDatabaseSettings->setEnabled(true);
|
2012-04-16 15:28:49 -04:00
|
|
|
m_ui->actionDatabaseSave->setEnabled(true);
|
|
|
|
m_ui->actionDatabaseSaveAs->setEnabled(true);
|
|
|
|
break;
|
|
|
|
case 1: // entry edit
|
|
|
|
case 2: // group edit
|
|
|
|
case 3: // change master key
|
2012-04-19 10:20:20 -04:00
|
|
|
case 4: // database settings
|
2012-04-16 15:28:49 -04:00
|
|
|
m_ui->actionEntryNew->setEnabled(false);
|
|
|
|
m_ui->actionGroupNew->setEnabled(false);
|
|
|
|
m_ui->actionEntryEdit->setEnabled(false);
|
|
|
|
m_ui->actionGroupEdit->setEnabled(false);
|
|
|
|
m_ui->actionEntryDelete->setEnabled(false);
|
2012-04-21 13:06:28 -04:00
|
|
|
m_ui->actionGroupDelete->setEnabled(false);
|
2012-04-16 15:28:49 -04:00
|
|
|
m_ui->actionChangeMasterKey->setEnabled(false);
|
2012-04-19 10:20:20 -04:00
|
|
|
m_ui->actionChangeDatabaseSettings->setEnabled(false);
|
2012-04-16 15:28:49 -04:00
|
|
|
m_ui->actionDatabaseSave->setEnabled(false);
|
|
|
|
m_ui->actionDatabaseSaveAs->setEnabled(false);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
Q_ASSERT(false);
|
|
|
|
}
|
|
|
|
m_ui->actionDatabaseClose->setEnabled(true);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
m_ui->actionEntryNew->setEnabled(false);
|
|
|
|
m_ui->actionGroupNew->setEnabled(false);
|
|
|
|
m_ui->actionEntryEdit->setEnabled(false);
|
|
|
|
m_ui->actionGroupEdit->setEnabled(false);
|
|
|
|
m_ui->actionEntryDelete->setEnabled(false);
|
2012-04-21 13:06:28 -04:00
|
|
|
m_ui->actionGroupDelete->setEnabled(false);
|
2012-04-16 15:28:49 -04:00
|
|
|
m_ui->actionChangeMasterKey->setEnabled(false);
|
2012-04-19 10:20:20 -04:00
|
|
|
m_ui->actionChangeDatabaseSettings->setEnabled(false);
|
2012-04-16 15:28:49 -04:00
|
|
|
m_ui->actionDatabaseSave->setEnabled(false);
|
|
|
|
m_ui->actionDatabaseSaveAs->setEnabled(false);
|
|
|
|
|
|
|
|
m_ui->actionDatabaseClose->setEnabled(false);
|
|
|
|
}
|
2011-11-16 12:47:17 -05:00
|
|
|
}
|
2012-04-11 14:35:52 -04:00
|
|
|
|
|
|
|
void MainWindow::closeEvent(QCloseEvent *event) {
|
|
|
|
if (!m_ui->tabWidget->closeAllDatabases()) {
|
|
|
|
event->ignore();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
event->accept();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-04-16 15:28:49 -04:00
|
|
|
|
|
|
|
|