DlgMacroRecordImp.cpp

Go to the documentation of this file.
00001 /***************************************************************************
00002  *   Copyright (c) 2002 Jürgen Riegel <juergen.riegel@web.de>              *
00003  *                                                                         *
00004  *   This file is part of the FreeCAD CAx development system.              *
00005  *                                                                         *
00006  *   This library is free software; you can redistribute it and/or         *
00007  *   modify it under the terms of the GNU Library General Public           *
00008  *   License as published by the Free Software Foundation; either          *
00009  *   version 2 of the License, or (at your option) any later version.      *
00010  *                                                                         *
00011  *   This library  is distributed in the hope that it will be useful,      *
00012  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00013  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00014  *   GNU Library General Public License for more details.                  *
00015  *                                                                         *
00016  *   You should have received a copy of the GNU Library General Public     *
00017  *   License along with this library; see the file COPYING.LIB. If not,    *
00018  *   write to the Free Software Foundation, Inc., 59 Temple Place,         *
00019  *   Suite 330, Boston, MA  02111-1307, USA                                *
00020  *                                                                         *
00021  ***************************************************************************/
00022 
00023 
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <QMessageBox>
00027 # include <QDir>
00028 #endif
00029 
00030 #include "Macro.h"
00031 #include "Application.h"
00032 #include "MainWindow.h"
00033 #include "DlgMacroRecordImp.h"
00034 #include "FileDialog.h"
00035 
00036 
00037 using namespace Gui::Dialog;
00038 
00039 /* TRANSLATOR Gui::Dialog::DlgMacroRecordImp */
00040 
00048 DlgMacroRecordImp::DlgMacroRecordImp( QWidget* parent, Qt::WFlags fl )
00049     : QDialog(parent, fl), WindowParameter("Macro")
00050 {
00051     this->setupUi(this);
00052 
00053     // get the macro home path
00054     this->macroPath = QString::fromUtf8(getWindowParameter()->GetASCII("MacroPath",
00055         App::Application::getUserAppDataDir().c_str()).c_str());
00056     // check on PATHSEP at the end
00057     if (this->macroPath.at(this->macroPath.length()-1) != QLatin1Char(PATHSEP))
00058         this->macroPath += QLatin1Char(PATHSEP);
00059 
00060     // set the edit fields
00061     this->lineEditMacroPath->setText(macroPath);
00062 
00063     // get a pointer to the macro manager
00064     this->macroManager = Application::Instance->macroManager();
00065 
00066     // check if a macro recording is in progress
00067     this->macroManager->isOpen() ? buttonStart->setEnabled(false) : buttonStop->setEnabled(false);
00068 }
00069 
00073 DlgMacroRecordImp::~DlgMacroRecordImp()
00074 {
00075     // no need to delete child widgets, Qt does it all for us
00076 }
00077 
00081 void DlgMacroRecordImp::on_buttonStart_clicked()
00082 {
00083     // test if the path already set
00084     if (lineEditPath->text().isEmpty()) {
00085         QMessageBox::information(getMainWindow(), tr("Macro recorder"),
00086             tr("Specify first a place to save."));
00087         return;
00088     }
00089 
00090     QDir dir(macroPath);
00091     if (!dir.exists()) {
00092         QMessageBox::information(getMainWindow(), tr("Macro recorder"),
00093             tr("The macro directory doesn't exist. Please, choose another one."));
00094         return;
00095     }
00096 
00097     // search in the macro path first for an already existing macro
00098     QString fn = this->macroPath + lineEditPath->text();
00099     if (!fn.endsWith(QLatin1String(".FCMacro")) ) fn += QLatin1String(".FCMacro");
00100     QFileInfo fi(fn);
00101     if ( fi.isFile() && fi.exists() )
00102     {
00103         if (QMessageBox::question(this, tr("Existing macro"),
00104                 tr("The macro '%1' already exists. Do you want to overwrite?").arg(fn),
00105                 QMessageBox::Yes,
00106                 QMessageBox::No|
00107                 QMessageBox::Default|
00108                 QMessageBox::Escape) == QMessageBox::No)
00109         return;
00110     }
00111 
00112     // open the macro recording
00113     this->macroManager->open(MacroManager::File, fn.toUtf8().constData());
00114     accept();
00115 }
00116 
00120 void DlgMacroRecordImp::on_buttonCancel_clicked()
00121 {
00122     if (this->macroManager->isOpen()) {
00123         this->macroManager->cancel();
00124     }
00125   
00126     QDialog::reject();
00127 }
00128 
00132 void DlgMacroRecordImp::on_buttonStop_clicked()
00133 {
00134     if(this->macroManager->isOpen()) {
00135         // ends the macrorecording and save the file...
00136         this->macroManager->commit();
00137     }
00138 
00139     QDialog::accept();
00140 }
00141 
00142 void DlgMacroRecordImp::on_pushButtonChooseDir_clicked()
00143 {
00144     QString newDir = QFileDialog::getExistingDirectory(0,tr("Choose macro directory"),macroPath);
00145     if (!newDir.isEmpty()) {
00146         macroPath = QDir::convertSeparators(newDir + QDir::separator());
00147         this->lineEditMacroPath->setText(macroPath);
00148         getWindowParameter()->SetASCII("MacroPath",macroPath.toUtf8());
00149     }
00150 }
00151 
00152 void DlgMacroRecordImp::on_lineEditMacroPath_textChanged (const QString & newDir)
00153 {
00154     macroPath = newDir;
00155 }
00156 
00157 
00158 #include "moc_DlgMacroRecordImp.cpp"
00159 

Generated on Wed Nov 23 19:00:06 2011 for FreeCAD by  doxygen 1.6.1