Main Page   Class Hierarchy   Data Structures   File List   Data Fields  

addnewstock.cpp

00001 /***************************************************************************
00002                           addnewstock.cpp  -  description
00003                              -------------------
00004     begin                : Sun Oct 20 2002
00005     copyright            : (C) 2002 by Michael Otto
00006     email                : Michael.Otto@saskathex.de
00007  ***************************************************************************/
00008 
00009 /***************************************************************************
00010  *                                                                         *
00011  *   This program is free software; you can redistribute it and/or modify  *
00012  *   it under the terms of the GNU General Public License as published by  *
00013  *   the Free Software Foundation; either version 2 of the License, or     *
00014  *   (at your option) any later version.                                   *
00015  *                                                                         *
00016  ***************************************************************************/
00017 
00018 #include "addnewstock.h"
00019 
00020 #include "stockmarketvector.h"
00021 #include "stockmarket.h"
00022 #include "stock.h"
00023 
00024 #include <gtkmm/stock.h>
00025 
00026 #include "config.h"
00027 
00031 AddNewStock::AddNewStock(const StockMarketVector * const stockMarketVector) {
00032 
00033   AddNewStock::stockMarketVector = stockMarketVector;
00034 
00035   set_title("adding stock");
00036   set_border_width(5);
00037   set_resizable(false);
00038   set_modal(true);
00039   
00040   vbox = manage(new Gtk::VBox(false, 0));
00041   vbox->set_spacing(5);
00042   add (*vbox);
00043 
00044   if (stockMarketVector->getNumberOfStockMarkets() > 0) {
00045     label = manage (new Gtk::Label("Select a market:", 0));
00046     vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00047     hSep = manage(new Gtk::HSeparator());
00048     vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00049     vboxChoice = manage(new Gtk::VBox(false, 0));
00050 
00051     radioButtons.clear();
00052     Gtk::RadioButton::Group group;
00053     Gtk::RadioButton *rb;
00054     for (int i = 0; i < stockMarketVector->getNumberOfStockMarkets(); i++) {
00055       StockMarket *stockMarket = stockMarketVector->getStockMarket(i);
00056       rb = manage( new Gtk::RadioButton(group, stockMarket->getMarketName()));
00057       radioButtons.push_back(rb);
00058       vboxChoice->pack_start(*rb, Gtk::PACK_SHRINK, 0);
00059     }
00060     vbox->pack_start(*vboxChoice, Gtk::PACK_SHRINK, 0);
00061     hSep = manage(new Gtk::HSeparator());
00062     vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00063     hButtonBox = manage( new Gtk::HButtonBox());
00064     hButtonBox->set_spacing(5);
00065     vbox->pack_start(*hButtonBox, Gtk::PACK_SHRINK, 0);
00066     buttonCancel = manage( new Gtk::Button(Gtk::Stock::CANCEL));
00067     buttonCancel->signal_clicked().connect(slot(*this,&AddNewStock::quit));
00068     hButtonBox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00069     buttonNext = manage( new Gtk::Button(Gtk::Stock::GO_FORWARD));
00070     buttonNext->signal_clicked().connect(slot(*this,&AddNewStock::editStockValue));
00071     hButtonBox->pack_start(*buttonNext, Gtk::PACK_SHRINK, 0);
00072   } else {
00073     set_title("Message");
00074     label = manage (new Gtk::Label("There are no markets!"));
00075     vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00076     buttonCancel = manage(new Gtk::Button(Gtk::Stock::OK));
00077     buttonCancel->signal_clicked().connect(slot(*this,&AddNewStock::quit));
00078     vbox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00079   }
00080   show_all();
00081 }
00082 
00086 AddNewStock::~AddNewStock() {
00087 }
00088 
00089 
00093 void AddNewStock::quit() {
00094   delete this;
00095 }
00096 
00102 void AddNewStock::editStockValue() {
00103 
00104   Gtk::RadioButton *rb;
00105   for (int i = 0; i < radioButtons.size(); i++) {
00106     rb = radioButtons[i];
00107     if (rb->get_active()) {
00108       stockMarket = stockMarketVector->getStockMarket(i);
00109 #ifdef DEBUG
00110       cout << "selected "<< stockMarket->getMarketName() << endl;
00111 #endif
00112     }
00113   }
00114   for (int i = 0; i < radioButtons.size(); i++) {
00115     rb = radioButtons[i];
00116     delete rb;
00117   }
00118   radioButtons.clear();
00119 
00120   delete vbox;
00121   Gtk::Adjustment *adjustmentNumber, *adjustmentBuyValue, *adjustmentBuyCost;
00122   vbox = manage(new Gtk::VBox(false, 0));
00123   vbox->set_spacing(5);
00124   add(*vbox);
00125   label = manage (new Gtk::Label("Enter stock values:", 0));
00126   vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00127   hSep = manage(new Gtk::HSeparator());
00128   vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00129   tableEditStockValue = manage(new Gtk::Table(2, 6, false));
00130   tableEditStockValue->set_spacings(5);
00131   vbox->pack_start(*tableEditStockValue, Gtk::PACK_EXPAND_WIDGET, 0);
00132   label = manage (new Gtk::Label("Name", 0));
00133   tableEditStockValue->attach(*label, 0, 1, 0, 1);
00134   label = manage (new Gtk::Label("ID/WKN", 0));
00135   tableEditStockValue->attach(*label, 0, 1, 1, 2);
00136   label = manage (new Gtk::Label("Date of Purchase", 0));
00137   tableEditStockValue->attach(*label, 0, 1, 2, 3);
00138   label = manage (new Gtk::Label("Amount", 0));
00139   tableEditStockValue->attach(*label, 0, 1, 3, 4);
00140   label = manage (new Gtk::Label("Buying Rate", 0));
00141   tableEditStockValue->attach(*label, 0, 1, 4, 5);
00142   label = manage (new Gtk::Label("Purchase Cost", 0));
00143   tableEditStockValue->attach(*label, 0, 1, 5, 6);
00144   entryName = manage (new Gtk::Entry());
00145   entryName->set_text("name");
00146   entryName->set_max_length(20);
00147   entryName->set_width_chars(20);
00148   tableEditStockValue->attach(*entryName, 1, 2, 0, 1);
00149   entryWkn = manage (new Gtk::Entry());
00150   entryWkn->set_text("id/wkn");
00151   entryWkn->set_max_length(10);
00152   entryWkn->set_width_chars(10);
00153   tableEditStockValue->attach(*entryWkn, 1, 2, 1, 2);
00154   entryBuyingDate = manage (new Gtk::Entry());
00155   entryBuyingDate->set_text("yyyy/mm/dd");
00156   entryBuyingDate->set_max_length(10);
00157   entryBuyingDate->set_width_chars(10);
00158   tableEditStockValue->attach(*entryBuyingDate, 1, 2, 2, 3);
00159   adjustmentNumber = manage(new Gtk::Adjustment(0, 0, 10000, 1, 10, 10));
00160   spinbuttonNumber = manage(new Gtk::SpinButton(*adjustmentNumber, 1, 0));
00161   tableEditStockValue->attach(*spinbuttonNumber, 1, 2, 3, 4);
00162   adjustmentBuyValue = manage(new Gtk::Adjustment(0, 0, 10000, 0.01, 10, 10));
00163   spinbuttonBuyValue = manage(new Gtk::SpinButton(*adjustmentBuyValue, 1, 0));
00164   spinbuttonBuyValue->set_digits(2);
00165   tableEditStockValue->attach(*spinbuttonBuyValue, 1, 2, 4, 5);
00166   adjustmentBuyCost = manage(new Gtk::Adjustment(0, 0, 10000, 0.01, 10, 10));
00167   spinbuttonBuyCost = manage(new Gtk::SpinButton(*adjustmentBuyCost, 1, 0));
00168   spinbuttonBuyCost->set_digits(2);
00169   tableEditStockValue->attach(*spinbuttonBuyCost, 1, 2, 5, 6);
00170   hSep = manage(new Gtk::HSeparator());
00171   vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00172   hButtonBox = manage( new Gtk::HButtonBox());
00173   hButtonBox->set_spacing(5);
00174   vbox->pack_start(*hButtonBox, Gtk::PACK_SHRINK, 0);
00175   buttonCancel = manage( new Gtk::Button(Gtk::Stock::CANCEL));
00176   buttonCancel->signal_clicked().connect(slot(*this,&AddNewStock::quit));
00177   hButtonBox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00178   buttonFinish = manage( new Gtk::Button(Gtk::Stock::OK));
00179   buttonFinish->signal_clicked().connect(slot(*this,&AddNewStock::finishNewStock));
00180   hButtonBox->pack_start(*buttonFinish, Gtk::PACK_SHRINK, 0);
00181   show_all();
00182 }
00183 
00189 void AddNewStock::finishNewStock() {
00190   Glib::ustring c1 = entryName->get_text();
00191   Glib::ustring c2 = entryWkn->get_text();
00192   Glib::ustring c3 = entryBuyingDate->get_text();
00193   string c4 = locale_from_utf8 (c1);
00194   string c5 = locale_from_utf8 (c2);
00195   string c6 = locale_from_utf8 (c3);
00196   stockMarket->addStock( Stock(c4, c5, c6, spinbuttonNumber->get_value_as_int(),
00197                               (float) spinbuttonBuyValue->get_value(),
00198                               (float) spinbuttonBuyCost->get_value(),
00199                               (float) spinbuttonBuyValue->get_value()));
00200   quit();
00201 }
00202 
00207 bool AddNewStock::on_delete_event(GdkEventAny *event) {
00208   quit();
00209   return true;
00210 }

Generated on Tue May 27 21:24:01 2003 for gstockcalc by doxygen1.3-rc3