#include #include #include #include #include #include #include #include #include #include #include #define T(String) gettext(String) using namespace std; /** * Application class */ class Application { private: Glib::RefPtr glade; Gtk::Window * winInit; Gtk::Window * winProgress; Gtk::Window * winMessage; Gtk::ProgressBar * pbarInitializing; Gtk::TextView * viewConsole; Glib::Mutex text_buffer_mutex; deque text_buffer; Glib::Dispatcher signal_output_available; bool spawn_completed; int spawn_status; public: /** * Constructor */ Application() { cout<<"* Welcome to lliurex openmeetings"<query_exists()) { glade_path="interface.glade"; } else { if(Gio::File::create_for_path("/usr/share/lliurex-openmeetings/service-rsrc/interface.glade")->query_exists()) { glade_path="/usr/share/lliurex-openmeetings/setup-rsrc/interface.glade"; } else { cerr<<"Can't find glade resource"<get_widget("winInit",winInit); glade->get_widget("winProgress",winProgress); glade->get_widget("winMessage",winMessage); glade->get_widget("pbarInitializing",pbarInitializing); glade->get_widget("viewConsole",viewConsole); winInit->signal_delete_event().connect(sigc::mem_fun(*this,&Application::OnWinInitClose)); Gtk::Button * button; glade->get_widget("btnInit",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::OnBtnInitClick)); glade->get_widget("btnMessageOk",button); button->signal_clicked().connect(sigc::mem_fun(*this,&Application::OnBtnMessageOkClick)); Glib::signal_timeout().connect(sigc::mem_fun(*this,&Application::OnTimer), 500); signal_output_available.connect(sigc::mem_fun(*this,&Application::OnOutputAvailable)); winInit->show_all(); } /** * Destructor */ ~Application() { cout<<"* bye"< data; bool is_ok=true; cout<<"* initializing..."<get_widget("lblWarning",lblWarning); glade->get_widget("txtDBUser",txtDBUser); glade->get_widget("txtDBPass",txtDBPass); glade->get_widget("txtDBPass2",txtDBPass2); glade->get_widget("txtAdminUser",txtAdminUser); glade->get_widget("txtAdminPass",txtAdminPass); glade->get_widget("txtAdminPass2",txtAdminPass2); glade->get_widget("txtEmail",txtEmail); data["db_user"]=txtDBUser->get_text(); data["db_pass"]=txtDBPass->get_text(); data["admin"]=txtAdminUser->get_text(); data["password"]=txtAdminPass->get_text(); data["email"]=txtEmail->get_text(); try { if(data["db_user"]=="root")throw string(T("root is not a valid database user")); if(data["db_user"].length()<4)throw string(T("Database user should have at least, four characters")); if(data["db_pass"].length()<4)throw string(T("Database password should have at least, four characters")); if(data["db_pass"]!=txtDBPass2->get_text())throw string(T("Database passwords do not match")); if(data["admin"].length()<4)throw string(T("Admin user should have at least, four characters")); if(data["password"].length()<4)throw string(T("Admin password should have at least, four characters")); if(data["password"]!=txtAdminPass2->get_text())throw string(T("Admin passwords do not match")); /* I had a problem, I used regex. Now I have two problems * Following regex expression checks whenever is a valid email address... * at least it was designed with that in mind * */ Glib::RefPtr regex = Glib::Regex::create("^[[:alnum:]_]+@[[:alnum:]]+\\.[[:alnum:]]+(\\.[[:alnum:]]+)*$"); if(!regex->match(data["email"]))throw string(T("Invalid email address")); } catch(string & e) { lblWarning->set_text(e); is_ok=false; } /* if settings are ok we can Initialize openmeetings and wait patiently */ if(is_ok) { lblWarning->set_text(""); WriteSetup(data); winInit->hide(); winProgress->show_all(); spawn_completed=false; Glib::Thread::create(sigc::mem_fun(*this, &Application::SubProcess)); } } /** * Message button hook */ void OnBtnMessageOkClick() { Gtk::Main::quit(); } /** * Timer Tick */ int OnTimer() { /* once process is gone, we show message window and stop this timer */ if(spawn_completed) { /* message box is customized in case of wrong output status */ if(spawn_status!=0) { Gtk::Label * lblMessage; glade->get_widget("lblMessage",lblMessage); Gtk::Image * imgMessage; glade->get_widget("imgMessage",imgMessage); lblMessage->set_text(T("There was an error while setting openmeetings up, check output for details")); imgMessage->set_from_icon_name("dialog-error",Gtk::IconSize(Gtk::ICON_SIZE_DIALOG)); } winMessage->show_all(); return 0; } pbarInitializing->pulse(); return 1; } /** * Writes setup file to /tmp */ void WriteSetup(map & data) { ofstream file; file.open ("/tmp/lliurex-openmeetings.conf"); file << "[openmeetings]\n"; for(pair & node : data) { file<get_buffer()->end(); it=viewConsole->get_buffer()->insert(it,text); viewConsole->scroll_to(it); } /** * Spawns initialization script (from a thread) */ void SubProcess() { /* credits goes for: R Samuel Klatchko * from StackOverflow * */ int pipefd[2]; int r=pipe(pipefd); if(r==-1) { cerr<<"* Failed to create pipe"<