00001
00002
00003
00004
00005
00006
00007
00008 #ifndef CSVMODULE_H
00009 #define CSVMODULE_H
00010
00011 #include "../TableDataSourceCSV.h"
00012
00013 #include <iostream>
00014 #include <fstream>
00015
00016 namespace Impala { namespace Application { namespace MediaTable {
00017
00018 class CSVModule : public TableDataSourceModule {
00019 public:
00020 CSVModule() : TableDataSourceModule("CSV") {}
00021
00022 void ButtonSelectionEvent(OglGui::Button *src, void *userData)
00023 {
00024 if(src->GetLabel() == "New " + GetName())
00025 {
00026 StoreConfigWindowValues();
00027 if(mStringValues["Name"] == "")
00028 {
00029 SetErrorMessage(mConfigWindow, "Name can not be empty.");
00030 return;
00031 }
00032 if(mStringValues["Filename"] == "")
00033 {
00034 SetErrorMessage(mConfigWindow, "Filename can not be empty.");
00035 return;
00036 } else {
00037 std::ifstream is(mStringValues["Filename"].c_str());
00038 bool good = is.good();
00039 is.close();
00040 if(!good) {
00041 SetErrorMessage(mConfigWindow, "Can not open file " + mStringValues["Filename"]);
00042 return;
00043 }
00044 }
00045 DoHandleNewTableDataSource();
00046 delete mConfigWindow;
00047 DoReleaseConfigWindow();
00048 }
00049 else
00050 TableDataSourceModule::ButtonSelectionEvent(src, userData);
00051 }
00052
00053 void ModuleSelected()
00054 {
00055 TableDataSourceModule::DrawConfigWindow();
00056 OglGui::GroupBox* grp = new OglGui::GroupBox(mConfigWindow, mConfigWindow->W()-2, 362, "");
00057
00058 AddTextField(grp, "Name");
00059 AddTextField(grp, "Filename");
00060
00061 (new OglGui::Button(grp, grp->W()-4, 26, "New "+GetName(), BEV_ETCHED))
00062 ->SetButtonListener(this);
00063
00064 grp->RepositionViewports();
00065 grp->ScaleChildren();
00066 }
00067
00068 TableDataSource* NewTableDataSource()
00069 {
00070 TableDataSource* source;
00071 source = new TableDataSourceCSV(mStringValues["Filename"]);
00072 TableDataStore* store = TableDataStore::GetInstance();
00073 store->AddTableDataSource(mStringValues["Name"], source);
00074 return source;
00075 }
00076 };
00077
00078 } } }
00079
00080
00081 #endif // CSVMODULE_H