lib/SpreadDialog.cpp

Go to the documentation of this file.
00001 /*
00002  *  Qtstalker stock charter
00003  *
00004  *  Copyright (C) 2001-2007 Stefan S. Stratigakos
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program 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 General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
00019  *  USA.
00020  */
00021 
00022 #include "SpreadDialog.h"
00023 #include "HelpWindow.h"
00024 #include "Config.h"
00025 #include "DbPlugin.h"
00026 #include <qlayout.h>
00027 #include <qinputdialog.h>
00028 #include <qdir.h>
00029 #include <qmessagebox.h>
00030 #include <qlabel.h>
00031 
00032 SpreadDialog::SpreadDialog (QString &nam, QString &fs, QString &ss) : QTabDialog (0, "SpreadDialog", TRUE)
00033 {
00034   helpFile = "spread.html";
00035 
00036   setCaption(tr("Spread Dialog"));
00037   
00038   QWidget *w = new QWidget(this);
00039   
00040   QVBoxLayout *vbox = new QVBoxLayout(w);
00041   vbox->setMargin(5);
00042   vbox->setSpacing(0);
00043 
00044   QGridLayout *grid = new QGridLayout(vbox, 1, 2);
00045   grid->setSpacing(5);
00046   grid->setColStretch(1, 1);
00047 
00048   QLabel *label = new QLabel(tr("Name"), w);
00049   grid->addWidget(label, 0, 0);
00050 
00051   name = new QLineEdit(nam, w);
00052   grid->addWidget(name, 0, 1);
00053 
00054   label = new QLabel(tr("First Symbol"), w);
00055   grid->addWidget(label, 1, 0);
00056 
00057   Config config;
00058   QString path;
00059   config.getData(Config::DataPath, path);
00060 
00061   firstSymbol = new SymbolButton(w, path, fs);
00062   grid->addWidget(firstSymbol, 1, 1);
00063 
00064   label = new QLabel(tr("Second Symbol"), w);
00065   grid->addWidget(label, 2, 0);
00066 
00067   secondSymbol = new SymbolButton(w, path, ss);
00068   grid->addWidget(secondSymbol, 2, 1);
00069   
00070   vbox->insertStretch(-1, 1);
00071   
00072   addTab(w, tr("Settings"));
00073 
00074   setOkButton();
00075   setCancelButton();
00076   setHelpButton();
00077   QObject::connect(this, SIGNAL(helpButtonPressed()), this, SLOT(help()));
00078 
00079   resize(400, 300);
00080 }
00081 
00082 SpreadDialog::SpreadDialog () : QTabDialog (0, "SpreadDialog", TRUE)
00083 {
00084 }
00085 
00086 SpreadDialog::~SpreadDialog ()
00087 {
00088 }
00089 
00090 void SpreadDialog::newSpread ()
00091 {
00092   bool ok = FALSE;
00093   QString spread = QInputDialog::getText(QObject::tr("New Spread"),
00094                                          QObject::tr("Enter symbol name for the new Spread"),
00095                                          QLineEdit::Normal,
00096                                          QString::null,
00097                                          &ok,
00098                                          0);
00099   if (! spread.length() || ok == FALSE)
00100     return;
00101 
00102   QDir dir;
00103   Config config;
00104   QString s;
00105   config.getData(Config::DataPath, s);
00106   s.append("/Spread");
00107   if (! dir.exists(s))
00108   {
00109     if (! dir.mkdir(s, TRUE))
00110     {
00111       QMessageBox::information(0,
00112                                QObject::tr("Qtstalker: Error"),
00113                                QObject::tr("Could not create Spread directory."));
00114       return;
00115     }
00116   }
00117   
00118   s.append("/" + spread);
00119   if (dir.exists(s))
00120   {
00121     QMessageBox::information(0,
00122                              QObject::tr("Qtstalker: Error"),
00123                              QObject::tr("This Spread already exists."));
00124     return;
00125   }
00126 
00127   DbPlugin db;
00128   if (db.openChart(s))
00129   {
00130     QMessageBox::information(0,
00131                              QObject::tr("Qtstalker: Disk Error"),
00132                              QObject::tr("Cannot create chart."));
00133     db.close();
00134     return;
00135   }
00136 
00137   db.setHeaderField(DbPlugin::Symbol, spread);
00138   s = "Spread";
00139   db.setHeaderField(DbPlugin::Type, s);  
00140   db.setHeaderField(DbPlugin::Plugin, s);  
00141   db.setHeaderField(DbPlugin::Title, spread);
00142   db.close();
00143 }
00144 
00145 void SpreadDialog::help ()
00146 {
00147   HelpWindow *hw = new HelpWindow(this, helpFile);
00148   hw->show();
00149 }
00150 
00151 void SpreadDialog::getName (QString &d)
00152 {
00153   d = name->text();
00154 }
00155 
00156 void SpreadDialog::getFirstSymbol (QString &d)
00157 {
00158   firstSymbol->getPath(d);
00159 }
00160 
00161 void SpreadDialog::getSecondSymbol (QString &d)
00162 {
00163   secondSymbol->getPath(d);
00164 }
00165 
00166