00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "infodialog.h"
00019
00020 #include "stock.h"
00021 #include "config.h"
00022
00023 #include <gtkmm/stock.h>
00024
00028 InfoDialog::InfoDialog(Stock * const stock){
00029 InfoDialog::stock = stock;
00030
00031 Gtk::VBox *vbox, *vboxChoice;
00032 Gtk::Button *buttonCancel, *buttonFinish;
00033 Gtk::HButtonBox *hButtonBox;
00034 Gtk::Table *tableEditStockValue;
00035 Gtk::HSeparator *hSep;
00036 Gtk::Label *label;
00037 Gtk::Adjustment *adjustmentAmount, *adjustmentBuyingRate, *adjustmentPurchaseCost;
00038
00039 set_title(stock->getName());
00040 set_border_width(5);
00041 set_resizable(false);
00042 set_modal(true);
00043
00044 vbox = manage(new Gtk::VBox(false, 0));
00045 vbox->set_spacing(5);
00046 add(*vbox);
00047 adjustmentAmount = new Gtk::Adjustment(0, 0, 10000, 1, 10, 10);
00048 adjustmentBuyingRate = new Gtk::Adjustment(0, 0, 10000, 0.01, 10, 10);
00049 adjustmentPurchaseCost = new Gtk::Adjustment(0, 0, 10000, 0.01, 10, 10);
00050 tableEditStockValue = manage(new Gtk::Table(2, 6, false));
00051 tableEditStockValue->set_spacings(5);
00052 vbox->pack_start(*tableEditStockValue, Gtk::PACK_EXPAND_WIDGET, 0);
00053 label = manage (new Gtk::Label("Name", 0));
00054 tableEditStockValue->attach(*label, 0, 1, 0, 1);
00055 label = manage (new Gtk::Label("WKN", 0));
00056 tableEditStockValue->attach(*label, 0, 1, 1, 2);
00057 label = manage (new Gtk::Label("Date of Purchase", 0));
00058 tableEditStockValue->attach(*label, 0, 1, 2, 3);
00059 label = manage (new Gtk::Label("Amount", 0));
00060 tableEditStockValue->attach(*label, 0, 1, 3, 4);
00061 label = manage (new Gtk::Label("Buying Rate", 0));
00062 tableEditStockValue->attach(*label, 0, 1, 4, 5);
00063 label = manage (new Gtk::Label("Purchase Cost", 0));
00064 tableEditStockValue->attach(*label, 0, 1, 5, 6);
00065
00066 entryName = manage (new Gtk::Entry());
00067 entryName->set_text(stock->getName());
00068 entryName->set_max_length(30);
00069 entryName->set_width_chars(30);
00070 tableEditStockValue->attach(*entryName, 1, 2, 0, 1);
00071 entryWkn = manage (new Gtk::Entry());
00072 entryWkn->set_text(stock->getWkn());
00073 entryWkn->set_max_length(10);
00074 entryWkn->set_width_chars(10);
00075 tableEditStockValue->attach(*entryWkn, 1, 2, 1, 2);
00076 entryBuyingDate = manage (new Gtk::Entry());
00077 entryBuyingDate->set_text(stock->getBuyingDate());
00078 entryBuyingDate->set_max_length(10);
00079 entryBuyingDate->set_width_chars(10);
00080 tableEditStockValue->attach(*entryBuyingDate, 1, 2, 2, 3);
00081
00082 spinButtonAmount = new Gtk::SpinButton(*adjustmentAmount, 1, 0);
00083 spinButtonAmount->set_value(stock->getAmount());
00084 tableEditStockValue->attach(*spinButtonAmount, 1, 2, 3, 4);
00085 spinButtonBuyingRate =new Gtk::SpinButton(*adjustmentBuyingRate, 1, 0);
00086 spinButtonBuyingRate->set_digits(2);
00087 spinButtonBuyingRate->set_value(stock->getBuyingRate());
00088 tableEditStockValue->attach(*spinButtonBuyingRate, 1, 2, 4, 5);
00089 spinButtonPurchaseCost = new Gtk::SpinButton(*adjustmentPurchaseCost, 1, 0);
00090 spinButtonPurchaseCost->set_digits(2);
00091 spinButtonPurchaseCost->set_value(stock->getPurchaseCost());
00092 tableEditStockValue->attach(*spinButtonPurchaseCost, 1, 2, 5, 6);
00093
00094 hSep = manage(new Gtk::HSeparator());
00095 vbox->pack_start(*hSep, Gtk::PACK_SHRINK, 0);
00096
00097 hButtonBox = manage( new Gtk::HButtonBox());
00098 hButtonBox->set_spacing(5);
00099 vbox->pack_start(*hButtonBox, Gtk::PACK_SHRINK, 0);
00100
00101 buttonCancel = manage( new Gtk::Button(Gtk::Stock::CANCEL));
00102 buttonCancel->signal_clicked().connect(slot(*this,&InfoDialog::quit));
00103 hButtonBox->pack_start(*buttonCancel, Gtk::PACK_SHRINK, 0);
00104 buttonFinish = manage( new Gtk::Button(Gtk::Stock::OK));
00105 buttonFinish->signal_clicked().connect(slot(*this,&InfoDialog::finish));
00106 hButtonBox->pack_start(*buttonFinish, Gtk::PACK_SHRINK, 0);
00107 show_all();
00108 }
00109
00113 InfoDialog::~InfoDialog(){
00114 }
00115
00116
00120 void InfoDialog::quit() {
00121 this->~InfoDialog();
00122 }
00123
00124
00128 void InfoDialog::finish() {
00129 Glib::ustring c1 = entryName->get_text();
00130 Glib::ustring c2 = entryWkn->get_text();
00131 Glib::ustring c3 = entryBuyingDate->get_text();
00132 string c4 = locale_from_utf8 (c1);
00133 string c5 = locale_from_utf8 (c2);
00134 string c6 = locale_from_utf8 (c3);
00135
00136 stock->setName(c4);
00137 stock->setWkn(c5);
00138 stock->setBuyingDate(c6);
00139 stock->setAmount(spinButtonAmount->get_value_as_int());
00140 stock->setBuyingRate((float) spinButtonBuyingRate->get_value());
00141 stock->setPurchaseCost((float) spinButtonPurchaseCost->get_value());
00142 #ifdef DEBUG
00143 Stock *s = stock;
00144 cout << s->getName() << " " << s->getWkn() << " " << s->getAmount() << " " << s->getBuyingRate() << " " << s->getPurchaseCost() << " " << s->getCurrentMarketPrice() << endl;
00145 #endif
00146 quit();
00147 }
00148
00149
00154 bool InfoDialog::on_delete_event(GdkEventAny *) {
00155 quit();
00156 return true;
00157 }