DlgMacroRecordImp.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
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
00040
00048 DlgMacroRecordImp::DlgMacroRecordImp( QWidget* parent, Qt::WFlags fl )
00049 : QDialog(parent, fl), WindowParameter("Macro")
00050 {
00051 this->setupUi(this);
00052
00053
00054 this->macroPath = QString::fromUtf8(getWindowParameter()->GetASCII("MacroPath",
00055 App::Application::getUserAppDataDir().c_str()).c_str());
00056
00057 if (this->macroPath.at(this->macroPath.length()-1) != QLatin1Char(PATHSEP))
00058 this->macroPath += QLatin1Char(PATHSEP);
00059
00060
00061 this->lineEditMacroPath->setText(macroPath);
00062
00063
00064 this->macroManager = Application::Instance->macroManager();
00065
00066
00067 this->macroManager->isOpen() ? buttonStart->setEnabled(false) : buttonStop->setEnabled(false);
00068 }
00069
00073 DlgMacroRecordImp::~DlgMacroRecordImp()
00074 {
00075
00076 }
00077
00081 void DlgMacroRecordImp::on_buttonStart_clicked()
00082 {
00083
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
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
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
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