Main Page   Class Hierarchy   Data Structures   File List   Data Fields  

removemarket.cpp

00001 /***************************************************************************
00002                           removemarket.cpp  -  description
00003                              -------------------
00004     begin                : Sat Jan 18 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 "removemarket.h"
00019 
00020 #include "stockmarketvector.h"
00021 #include "stockmarket.h"
00022 #include "stockcontainer.h"
00023 #include "stock.h"
00024 
00025 #include "config.h"
00026 
00027 #include <gtkmm/stock.h>
00028 
00032 RemoveMarket::RemoveMarket(StockMarketVector *stockMarketVector) {
00033 
00034   RemoveMarket::stockMarketVector = stockMarketVector;
00035 
00036   set_title("removing market");
00037   set_border_width(5);
00038   set_resizable(false);
00039   set_modal(true);
00040 
00041   vbox = manage(new Gtk::VBox(false, 0));
00042   vbox->set_spacing(5);
00043   add(*vbox);
00044 
00045 
00046   if (stockMarketVector->getNumberOfStockMarkets() > 0) {
00047 
00048     label = manage (new Gtk::Label("Select the market to be removed:", 0));
00049     vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00050     hSep = manage(new Gtk::HSeparator());
00051     vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00052     vboxChoice = manage(new Gtk::VBox(false, 0));
00053     radioButtons.clear();
00054     Gtk::RadioButton::Group group;
00055     Gtk::RadioButton *rb;
00056     for (int i = 0; i < stockMarketVector->getNumberOfStockMarkets(); i++) {
00057       StockMarket *stockMarket = stockMarketVector->getStockMarket(i);
00058       rb = manage( new Gtk::RadioButton(group, stockMarket->getMarketName()));
00059       radioButtons.push_back(rb);
00060       vboxChoice->pack_start(*rb, Gtk::PACK_SHRINK, 0);
00061     }
00062     vbox->pack_start(*vboxChoice, Gtk::PACK_SHRINK, 0);
00063     hSep = manage(new Gtk::HSeparator());
00064     vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00065     hButtonBox = manage( new Gtk::HButtonBox());
00066     hButtonBox->set_spacing(5);
00067     vbox->pack_start(*hButtonBox, Gtk::PACK_SHRINK, 0);
00068     buttonCancel = manage( new Gtk::Button(Gtk::Stock::CANCEL));
00069     buttonCancel->signal_clicked().connect(slot(*this,&RemoveMarket::quit));
00070     hButtonBox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00071     buttonNext = manage( new Gtk::Button(Gtk::Stock::OK));
00072     buttonNext->signal_clicked().connect(slot(*this,&RemoveMarket::removeMarket));
00073     hButtonBox->pack_start(*buttonNext, Gtk::PACK_SHRINK, 0);
00074   } else {
00075     set_title("Message");
00076     label = manage (new Gtk::Label("There are no markets!"));
00077     vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00078     buttonCancel = manage(new Gtk::Button(Gtk::Stock::OK));
00079     buttonCancel->signal_clicked().connect(slot(*this,&RemoveMarket::quit));
00080     vbox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00081   }
00082   show_all();
00083 }
00084 
00088 RemoveMarket::~RemoveMarket() {}
00089 
00093 void RemoveMarket::quit() {
00094   delete this;
00095 }
00096 
00100 void RemoveMarket::removeMarket() {
00101   Gtk::RadioButton *rb;
00102   for (int i = 0; i < radioButtons.size(); i++) {
00103     rb = radioButtons[i];
00104     if (rb->get_active()) {
00105       stockMarket = stockMarketVector->getStockMarket(i);
00106 #ifdef DEBUG
00107       cout << "selected " << stockMarket->getMarketName() << endl;
00108 #endif
00109     }
00110   }
00111   for (int i = 0; i < radioButtons.size(); i++) {
00112     rb = radioButtons[i];
00113     delete rb;
00114   }
00115   radioButtons.clear();
00116 
00117   delete vbox;
00118 
00119   vbox = manage(new Gtk::VBox(false, 0));
00120   vbox->set_spacing(5);
00121   add(*vbox);
00122 
00123 
00124   char c[80];
00125   sprintf(c,"Stock market to be removed: %s", stockMarket->getMarketName().c_str());
00126   label = manage (new Gtk::Label(c));
00127   vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00128   label = manage (new Gtk::Label("All stocks in the market are also removed!"));
00129   vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00130   label = manage (new Gtk::Label("Are you sure?"));
00131   vbox->pack_start(*label, Gtk::PACK_SHRINK, 0);
00132 
00133   hSep = manage(new Gtk::HSeparator());
00134   vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00135   
00136   
00137   hButtonBox = manage( new Gtk::HButtonBox());
00138   hButtonBox->set_spacing(5);
00139   vbox->pack_start(*hButtonBox, Gtk::PACK_SHRINK, 0);
00140 
00141   buttonCancel = manage( new Gtk::Button(Gtk::Stock::NO));
00142   buttonCancel->signal_clicked().connect(slot(*this,&RemoveMarket::quit));
00143   hButtonBox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00144   buttonFinish = manage( new Gtk::Button(Gtk::Stock::YES));
00145   buttonFinish->signal_clicked().connect(slot(*this,&RemoveMarket::finishRemoveMarket));
00146   hButtonBox->pack_start(*buttonFinish, Gtk::PACK_SHRINK, 0);
00147 
00148   show_all();
00149 }
00150 
00154 void RemoveMarket::finishRemoveMarket() {
00155   stockMarketVector->removeStockMarket(stockMarket);
00156   quit();
00157 }
00158 
00159 
00164 bool RemoveMarket::on_delete_event(GdkEventAny *event) {
00165   quit();
00166   return true;
00167 }

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