void DatabaseTabWidget::saveDatabaseAs(int index)
{
    if (index == -1) {
        index = currentIndex();
    }
    saveDatabaseAs(indexDatabase(index));
}
Esempio n. 2
0
bool DatabaseTabWidget::saveDatabase(Database* db)
{
    DatabaseManagerStruct& dbStruct = m_dbList[db];

    if (dbStruct.saveToFilename) {
        QSaveFile saveFile(dbStruct.canonicalFilePath);
        if (saveFile.open(QIODevice::WriteOnly)) {
            m_writer.writeDatabase(&saveFile, db);
            if (m_writer.hasError()) {
                MessageBox::critical(this, tr("Error"), tr("Writing the database failed.") + "\n\n"
                                     + m_writer.errorString());
                return false;
            }
            if (!saveFile.commit()) {
                MessageBox::critical(this, tr("Error"), tr("Writing the database failed.") + "\n\n"
                                     + saveFile.errorString());
                return false;
            }
        }
        else {
            MessageBox::critical(this, tr("Error"), tr("Writing the database failed.") + "\n\n"
                                 + saveFile.errorString());
            return false;
        }

        dbStruct.modified = false;
        updateTabName(db);
        return true;
    }
    else {
        return saveDatabaseAs(db);
    }
}
void DatabaseTabWidget::saveDatabase(Database* db)
{
    DatabaseManagerStruct& dbStruct = m_dbList[db];

    if (dbStruct.saveToFilename) {
        bool result = false;

        QSaveFile saveFile(dbStruct.filePath);
        if (saveFile.open(QIODevice::WriteOnly)) {
            m_writer.writeDatabase(&saveFile, db);
            result = saveFile.commit();
        }

        if (result) {
            dbStruct.modified = false;
            updateTabName(db);
        }
        else {
            MessageBox::critical(this, tr("Error"), tr("Writing the database failed.") + "\n\n"
                                 + saveFile.errorString());
        }
    }
    else {
        saveDatabaseAs(db);
    }
}
Esempio n. 4
0
bool DatabaseTabWidget::saveDatabaseAs(int index)
{
    if (index == -1) {
        index = currentIndex();
    }

    return saveDatabaseAs(indexDatabase(index));
}
Esempio n. 5
0
void MainWindow::createActions()
{
	openAction = new QAction(tr("&Otevřít seznam..."), this);
	openAction->setIcon(QIcon(":/images/fileopen.svg"));
	openAction->setShortcut(QKeySequence::Open);
	openAction->setStatusTip(tr("Otevřít existující soubor se seznamem"));
	QObject::connect(openAction, SIGNAL(triggered()),
					 mainWidget, SLOT(openDatabase()));

	saveAction = new QAction(QIcon(":/images/filesave.svg"),
							 tr("&Uložit seznam"), this);
	saveAction->setShortcut(QKeySequence::Save);
	QObject::connect(saveAction, SIGNAL(triggered()),
					 mainWidget, SLOT(saveDatabase()));

	saveAsAction = new QAction(QIcon(":/images/filesaveas.svg"),
							   tr("&Uložit seznam jako..."), this);
	saveAsAction->setShortcut(QKeySequence::SaveAs);
	QObject::connect(saveAsAction, SIGNAL(triggered()),
					 mainWidget, SLOT(saveDatabaseAs()));

	findAction = new QAction(tr("&Vyhledat položku..."), this);
	findAction->setIcon(QIcon(":/images/search.svg"));
	findAction->setShortcut(QKeySequence::Find);
	findAction->setStatusTip(tr("Vyhledat položku v otevřeném seznamu"));
	QObject::connect(findAction, SIGNAL(triggered()),
					 mainWidget, SLOT(findFile()));

	exportAction = new QAction(tr("&Exportovat seznam..."), this);
	exportAction->setIcon(QIcon(":/images/export.svg"));
	exportAction->setShortcut(QKeySequence("Ctrl+E"));
	exportAction->setStatusTip(tr("Exportovat seznam do HTML"));
	QObject::connect(exportAction, SIGNAL(triggered()),
					 mainWidget, SLOT(exportDatabase()));

	settingsAction = new QAction(tr("&Nastavení..."), this);
	settingsAction->setIcon(QIcon(":/images/settings.svg"));
	settingsAction->setStatusTip(tr("Upravit nastavení programu"));
	QObject::connect(settingsAction, SIGNAL(triggered()),
					 mainWidget, SLOT(editSettings()));

	viewPhoneListAction = new QAction(tr("&Zobrazit seznam linek..."), this);
	viewPhoneListAction->setIcon(QIcon(":/images/spreadsheet.svg"));
	QObject::connect(viewPhoneListAction, SIGNAL(triggered()),
					 mainWidget, SLOT(viewPhoneList()));

	aboutQtAction = new QAction(tr("O toolkitu &Qt"), this);
	aboutQtAction->setIcon(QIcon(":/images/qt.png"));
	aboutQtAction->setShortcut(QKeySequence(tr("Ctrl+Q")));
	QObject::connect(aboutQtAction, SIGNAL(triggered()),
					 qApp, SLOT(aboutQt()));
}