# # # add_file "res/forms/create_database.ui" # content [e7c80917906e8d77c0e217fcebeec3b03c0c309f] # # add_file "src/view/dialogs/CreateDatabase.cpp" # content [e6a023f1390c9bb787bd7b4794ceadff83e1867b] # # add_file "src/view/dialogs/CreateDatabase.h" # content [c2485ec2d5d7bfa7649810f3335d2eff06325cf6] # ============================================================ --- res/forms/create_database.ui e7c80917906e8d77c0e217fcebeec3b03c0c309f +++ res/forms/create_database.ui e7c80917906e8d77c0e217fcebeec3b03c0c309f @@ -0,0 +1,106 @@ + + CreateDatabase + + + + 0 + 0 + 396 + 152 + + + + + 0 + 0 + + + + Create a new monotone database + + + + + + Select save location + + + + + + Select a location where you want to save the database: + + + false + + + + + + + + + true + + + + + + + browse + + + + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + + buttonBox + accepted() + CreateDatabase + accept() + + + 248 + 254 + + + 157 + 274 + + + + + buttonBox + rejected() + CreateDatabase + reject() + + + 316 + 260 + + + 286 + 274 + + + + + ============================================================ --- src/view/dialogs/CreateDatabase.cpp e6a023f1390c9bb787bd7b4794ceadff83e1867b +++ src/view/dialogs/CreateDatabase.cpp e6a023f1390c9bb787bd7b4794ceadff83e1867b @@ -0,0 +1,122 @@ +/*************************************************************************** + * Copyright (C) 2008 by Thomas Keller * + * address@hidden * + * * + * 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 3 of the License, or * + * (at your option) any later version. * + * * + * 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 . * + ***************************************************************************/ + +#include "CreateDatabase.h" +#include "MonotoneManager.h" +#include "MonotoneUtil.h" +#include "Settings.h" + +#include +#include +#include + +CreateDatabase::CreateDatabase(QWidget * parent) : Dialog(parent) +{ + setupUi(this); + Dialog::init(); + + connect( + browseFiles, SIGNAL(clicked()), + this, SLOT(doBrowseFiles()) + ); +} + +CreateDatabase::~CreateDatabase() {} + +void CreateDatabase::accept() +{ + QString path = databasePath->text(); + + if (path.isEmpty()) + { + QMessageBox::warning( + this, + tr("Please select a save location"), + tr("Please select a location where the database should be saved."), + QMessageBox::Ok + ); + return; + } + + QFileInfo fi(path); + bool writable = fi.exists() && fi.isWritable(); + + if (!writable) + { + QFileInfo di(fi.dir(), "."); + writable = di.isWritable(); + } + + if (!writable) + { + QMessageBox::critical( + this, + tr("Cannot write file"), + tr("Cannot write to the given path - please select another location."), + QMessageBox::Ok + ); + return; + } + + // the user previously accepted to overwrite this file, so we can safely + // delete it + if (fi.exists()) + { + if (!QFile::remove(fi.filePath())) + { + QMessageBox::critical( + this, + tr("Cannot remove old path"), + tr("Cannot remove old path '%1'.").arg(fi.filePath()), + QMessageBox::Ok + ); + return; + } + } + + QStringList params; + params << "db" << "init" << "-d" << fi.filePath(); + QByteArray output; + + bool res = MonotoneManager::singleRun(Settings::getMtnBinaryPath(), params, output); + + if (!res) + { + QMessageBox::critical( + this, + tr("Cannot create database"), + tr("An error occured while creating the database:\n%1'.") + .arg(MonotoneUtil::stripMtnPrefix(QString(output))), + QMessageBox::Ok + ); + return; + } + + emit databaseCreated(path); + done(QDialog::Accepted); +} + +void CreateDatabase::doBrowseFiles() +{ + QString fileName = + QFileDialog::getSaveFileName(this, tr("Save Database"), + "database.mtn", + tr("Monotone databases (*.mtn *.db)")); + databasePath->setText(fileName); +} + ============================================================ --- src/view/dialogs/CreateDatabase.h c2485ec2d5d7bfa7649810f3335d2eff06325cf6 +++ src/view/dialogs/CreateDatabase.h c2485ec2d5d7bfa7649810f3335d2eff06325cf6 @@ -0,0 +1,40 @@ +/*************************************************************************** + * Copyright (C) 2008 by Thomas Keller * + * address@hidden * + * * + * 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 3 of the License, or * + * (at your option) any later version. * + * * + * 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 . * + ***************************************************************************/ + +#ifndef CREATE_DATABASE_H +#define CREATE_DATABASE_H + +#include "Dialog.h" +#include "ui_create_database.h" + +class CreateDatabase : public Dialog, private Ui::CreateDatabase +{ + Q_OBJECT +public: + CreateDatabase(QWidget *); + ~CreateDatabase(); + +signals: + void databaseCreated(const QString &); + +private slots: + void accept(); + void doBrowseFiles(); +}; + +#endif