Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) TimePoll

 

TimePoll is a web application that allows to do a time poll: a poll that is determined by the time an option is selected, where every visitor can change the selected option.

 

 

 

 

 

Downloads

 

 

 

 

 

 

Older downloads

 

Technical facts

 

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ./ToolTimePoll/ToolTimePollConsole.pro

 

include(../../ConsoleApplication.pri)

include(../../Libraries/Boost.pri)

include(../../Classes/CppAbout/CppAbout.pri)
include(../../Classes/CppFileIo/CppFileIo.pri)
include(../../Classes/CppHelp/CppHelp.pri)
include(../../Classes/CppMenuDialog/CppMenuDialog.pri)
include(../../Classes/CppRichelBilderbeekProgram/CppRichelBilderbeekProgram.pri)
include(../../Classes/CppTrace/CppTrace.pri)

include(../../Classes/CppCanvas/CppCanvas.pri)
include(../../Classes/CppImageCanvas/CppImageCanvas.pri)
#include(../../Classes/CppDotMatrix/CppDotMatrix.pri)
include(../../Classes/CppXml/CppXml.pri)
include(ToolAsciiArterConsole.pri )

SOURCES += main.cpp

 

 

 

 

 

Qt project file: ./ToolTimePoll/ToolTimePollDesktop.pro

 

include(../../DesktopApplication.pri)
include(../../Libraries/Boost.pri)
include(../../Libraries/GeneralConsole.pri)
include(../../Libraries/GeneralDesktop.pri)

#Specific, console
include(../../Classes/CppCanvas/CppCanvas.pri)
include(../../Classes/CppDotMatrix/CppDotMatrix.pri)
include(../../Classes/CppImageCanvas/CppImageCanvas.pri)
#
include(ToolAsciiArterDesktop.pri)

SOURCES += qtmain.cpp

 

 

 

 

 

Qt project file: ./ToolTimePoll/ToolTimePollWebsite.pro

 

include(../../Libraries/BoostAll.pri)
include(../../Libraries/Wt.pri)
include(../../WebApplication.pri)

include(../../Libraries/GeneralConsole.pri)
include(../../Libraries/GeneralWeb.pri)

include(../../Classes/CppStopWatch/CppStopWatch.pri)
include(../../Classes/CppWtServerPusher/CppWtServerPusher.pri)
include(../../Classes/CppWtTimedServerPusher/CppWtTimedServerPusher.pri)

include(ToolTimePollWebsite.pri)

SOURCES += wtmain.cpp

 

 

 

 

 

./ToolTimePoll/ToolTimePollConsole.pri

 

INCLUDEPATH += \
    ../../Tools/ToolTimePoll

SOURCES += \
    ../../Tools/ToolTimePoll/timepolldata.cpp \
    ../../Tools/ToolTimePoll/timepollmenudialog.cpp \

HEADERS += \
    ../../Tools/ToolTimePoll/timepolldata.h \
    ../../Tools/ToolTimePoll/timepollmenudialog.h \

OTHER_FILES += \
    ../../Tools/ToolTimePoll/Licence.txt

 

 

 

 

 

./ToolTimePoll/ToolTimePollDesktop.pri

 

include(../../Tools/ToolAsciiArter/ToolAsciiArterConsole.pri)

FORMS += \
    ../../Tools/ToolAsciiArter/qtasciiartermenudialog.ui \
    ../../Tools/ToolAsciiArter/qtasciiartermaindialog.ui


SOURCES += \
    ../../Tools/ToolAsciiArter/qtasciiartermenudialog.cpp \
    ../../Tools/ToolAsciiArter/qtasciiartermaindialog.cpp

HEADERS += \
    ../../Tools/ToolAsciiArter/qtasciiartermenudialog.h \
    ../../Tools/ToolAsciiArter/qtasciiartermaindialog.h

 

 

 

 

 

./ToolTimePoll/ToolTimePollWebsite.pri

 

include(../../Tools/ToolTimePoll/ToolTimePollConsole.pri)

SOURCES += \
    ../../Tools/ToolTimePoll/wttimepollmaindialog.cpp \
    ../../Tools/ToolTimePoll/wttimepollmenudialog.cpp \


HEADERS += \
    ../../Tools/ToolTimePoll/wttimepollmaindialog.h \
    ../../Tools/ToolTimePoll/wttimepollmenudialog.h

 

 

 

 

 

./ToolTimePoll/timepolldata.h

 

//---------------------------------------------------------------------------
/*
TimePoll, time polling server
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTimePoll.htm
//---------------------------------------------------------------------------
#ifndef TIMEPOLLDATA_H
#define TIMEPOLLDATA_H

#include <regex>
#include <vector>

#include <boost/shared_ptr.hpp>


namespace ribi {

struct Stopwatch;

namespace ToolTimePoll {

///\brief
///The data used by the WtBroadcastServer
///
///Data is a Singleton
struct Data
{
  ///Get the fractions of the times spent in each option
  const std::vector<double> GetFractions() const;

  ///Get the currently selected index
  int GetIndex() const { return m_index; }

  ///Get the Data its only instance
  static Data * GetInstance();

  ///Get the times spent in each option
  const std::vector<double> GetTimes() const;

  ///Set the currently selected option
  void SetIndex(const int index);

  private:
  ///Data contructor is private, as it suits a Singleton best
  Data(const int n_options = 3);

  ///The currently selected index
  int m_index;

  ///The only instance of Data
  static Data * m_instance;

  ///The mutex
  static std::recursive_mutex m_mutex;

  ///The accumulated times
  std::vector<double> m_times;

  ///The stopwatch keeping track of the times
  boost::shared_ptr<Stopwatch> m_stopwatch;

};

} //~namespace ToolTimePoll
} //~namespace ribi

#endif // TIMEPOLLDATA_H

 

 

 

 

 

./ToolTimePoll/timepolldata.cpp

 

#include "timepolldata.h"
#include "stopwatch.h"



ribi::ToolTimePoll::Data * ribi::ToolTimePoll::Data::m_instance = 0;

std::recursive_mutex ribi::ToolTimePoll::Data::m_mutex;

ribi::ToolTimePoll::Data::Data(const int n_options)
  : m_index(-1),
    m_times(n_options,0.0),
    m_stopwatch(new Stopwatch)
{

}

const std::vector<double> ribi::ToolTimePoll::Data::GetFractions() const
{
  std::lock_guard<std::recursive_mutex> lock(m_mutex);
  std::vector<double> v = GetTimes(); //Recursion: need std::recursive_mutex
  const double sum_time = std::accumulate(v.begin(),v.end(),0.0);

  if (sum_time != 0.0)
  {
    std::for_each(v.begin(),v.end(),
      [sum_time](double& d) { d/= sum_time; } );

  }
  return v;
}

ribi::ToolTimePoll::Data * ribi::ToolTimePoll::Data::GetInstance()
{
  if (m_instance == 0)
  {
    std::lock_guard<std::recursive_mutex> lock(m_mutex);
    //Double-lock idiom
    if (m_instance == 0)
    {
      m_instance = new Data;
    }
  }
  assert(m_instance);
  return m_instance;
}

const std::vector<double> ribi::ToolTimePoll::Data::GetTimes() const
{
  std::lock_guard<std::recursive_mutex> lock(m_mutex);
  std::vector<double> times = m_times;
  if (m_index != -1)
  {
    assert(m_index >= 0);
    assert(m_index < static_cast<int>(times.size()));
    assert(m_stopwatch);
    times[m_index]+=m_stopwatch->elapsed();
  }
  return times;
}

void ribi::ToolTimePoll::Data::SetIndex(const int index)
{
  std::lock_guard<std::recursive_mutex> lock(m_mutex);
  if (m_index != -1)
  {
    assert(m_index >= 0);
    assert(m_index < static_cast<int>(m_times.size()));
    assert(m_stopwatch);
    m_times[m_index] += m_stopwatch->elapsed();
  }
  m_stopwatch.reset(new Stopwatch);
  m_index = index;
}

 

 

 

 

 

./ToolTimePoll/timepollmenudialog.h

 

//---------------------------------------------------------------------------
/*
TimePoll, time polling server
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTimePoll.htm
//---------------------------------------------------------------------------
#ifndef TIMEPOLLMENUDIALOG_H
#define TIMEPOLLMENUDIALOG_H

#include <string>
#include <vector>

#include "about.h"

namespace ribi {
namespace ToolTimePoll {

///The GUI independent version of WtTimePollMainDialog
struct TimePollMenuDialog
{
  static std::vector<std::string> GetVersionHistory();
  static std::string GetVersion();
  static About GetAbout();
};

} //~namespace ToolTimePoll

} //~namespace ribi

#endif // TIMEPOLLMAINDIALOG_H

 

 

 

 

 

./ToolTimePoll/timepollmenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TimePoll, time polling server
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTimePoll.htm
//---------------------------------------------------------------------------
#include "about.h"
#include "stopwatch.h"
#include "timepollmenudialog.h"

ribi::About ribi::ToolTimePoll::TimePollMenuDialog::GetAbout()
{
  About a(
    "Richel Bilderbeek",
    "TimePoll",
    "time poll web application",
    "the 1th of August 2011",
    "2011-2015",
    "http://www.richelbilderbeek.nl/ToolTimePoll.htm",
    GetVersion(),
    GetVersionHistory());
  a.AddLibrary("Stopwatch version: " + Stopwatch::GetVersion());
  return a;
}

std::string ribi::ToolTimePoll::TimePollMenuDialog::GetVersion()
{
  return "5.0";
}

std::vector<std::string> ribi::ToolTimePoll::TimePollMenuDialog::GetVersionHistory()
{
  return {
    "2011-04-13: Version 0.1: initial version, the as-simple-as-possible version",
    "2011-04-13: Version 0.2: added About screen, added that when a new user logs in, he/she has the correct initial index",
    "2011-04-13: Version 1.0: displays which fraction of the time each option is chosen",
    "2011-04-13: Version 1.1: minor changes for WtWebsite",
    "2011-04-25: Version 1.2: removed Close button",
    "2011-06-11: Version 2.0: use Wt::WTimer in WtTimePollDialog",
    "2011-06-26: Version 2.1: use of WtSafeWTimer in WtTimePollDialog",
    "2011-07-26: Version 3.0: use of Wt::WServer::post as described in http://richelbilderbeek.nl/CppWtExample3.htm",
    "2011-07-27: Version 4.0: use of WtBroadcastServer",
    "2011-07-29: Version 4.1: fixed bug in WtBroadcastServer",
    "2011-08-01: Version 4.2: use of thread-safe data getting in WtBroadcastServer",
    "2011-08-05: Version 5.0: use of WtServerPusher and WtTimedServerPusher"
  };
}

 

 

 

 

 

./ToolTimePoll/wtmain.cpp

 

//---------------------------------------------------------------------------
/*
TimePoll, time polling server
Copyright (C) 2011-2014 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTimePoll.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <Wt/WApplication>
#include <Wt/WEnvironment>

#include "wtautoconfig.h"
#include "wttimepollmenudialog.h"
#pragma GCC diagnostic pop

struct WtTimePollApplication : public Wt::WApplication
{
  WtTimePollApplication(const Wt::WEnvironment& env);
};

WtTimePollApplication::WtTimePollApplication(
  const Wt::WEnvironment& env)
  : WApplication(env)
{
  setTitle("TimePoll");
  this->useStyleSheet("wt.css");
  root()->addWidget(new ribi::ToolTimePoll::WtTimePollMenuDialog);
}

Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
  return new WtTimePollApplication(env);
}

int main(int argc, char **argv)
{
  ribi::WtAutoConfig::SaveDefaultStylesheet();
  ribi::WtAutoConfig a(argc,argv,createApplication);
  return a.Run();
}

 

 

 

 

 

./ToolTimePoll/wttimepollmaindialog.h

 

//---------------------------------------------------------------------------
/*
TimePoll, time polling server
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTimePoll.htm
//---------------------------------------------------------------------------
#ifndef TIMEPOLLWTMAINDIALOG_H
#define TIMEPOLLWTMAINDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <Wt/WContainerWidget>

#include <boost/scoped_ptr.hpp>

#include "wtserverpusherclient.h"
#include "wttimedserverpusherclient.h"
#pragma GCC diagnostic pop

namespace Wt
{
  //namespace Chart { struct WCartesianChart; }
  struct WButtonGroup;
  struct WLabel;
}

namespace ribi {
namespace ToolTimePoll {

///TimePoll its main dialog
struct WtTimePollMainDialog
  : public Wt::WContainerWidget, WtServerPusherClient, WtTimedServerPusherClient
{
  WtTimePollMainDialog();

  private:
  ///The user interface
  struct Ui
  {
    Ui()
      : //m_chart(0),
        m_label1(0), m_label2(0), m_label3(0), m_group(0) {}
    //Wt::Chart::WCartesianChart * m_chart;
    Wt::WLabel * m_label1;
    Wt::WLabel * m_label2;
    Wt::WLabel * m_label3;
    Wt::WButtonGroup * m_group;
  } ui;

  ///Change the index of the radiogroup
  void OnChangeIndex();

  ///Show me
  void ShowMain();


  ///Event triggered by WtServerPusher
  void OnServerPush();

  ///Event triggered by WtTimedServerPusher
  void OnTimedServerPush();
};

} //~namespace ToolTimePoll

} //~namespace ribi

#endif // TIMEPOLLWTMAINDIALOG_H

 

 

 

 

 

./ToolTimePoll/wttimepollmaindialog.cpp

 

//---------------------------------------------------------------------------
/*
TimePoll, time polling server
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTimePoll.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <boost/lexical_cast.hpp>
#include <boost/numeric/conversion/cast.hpp>

#include <Wt/WBreak>
#include <Wt/WButtonGroup>
#include <Wt/WGroupBox>
#include <Wt/WLabel>
#include <Wt/WRadioButton>

#include "timepolldata.h"
#include "wtaboutdialog.h"
#include "wtserverpusher.h"
#include "wttimepollmaindialog.h"
#pragma GCC diagnostic pop

ribi::ToolTimePoll::WtTimePollMainDialog::WtTimePollMainDialog()
  : ui{}
{
  ShowMain();
  OnServerPush();
  OnTimedServerPush();
}

void ribi::ToolTimePoll::WtTimePollMainDialog::ShowMain()
{
  this->clear();
  this->setContentAlignment(Wt::AlignCenter);
  //ButtonGroup
  {
    Wt::WGroupBox * const container = new Wt::WGroupBox("Which option?",this);
    ui.m_group = new Wt::WButtonGroup(this);

    {
      Wt::WRadioButton * const button = new Wt::WRadioButton("A", container);
      new Wt::WBreak(container);
      ui.m_group->addButton(button,0);
    }
    {
      Wt::WRadioButton * const button = new Wt::WRadioButton("B", container);
      new Wt::WBreak(container);
      ui.m_group->addButton(button,1);
    }
    {
      Wt::WRadioButton * const button = new Wt::WRadioButton("C", container);
      new Wt::WBreak(container);
      ui.m_group->addButton(button,2);
    }

    ui.m_group->checkedChanged().connect(
      this,&ribi::ToolTimePoll::WtTimePollMainDialog::OnChangeIndex);
  }
  //Faked chart
  {
    ui.m_label1 = new Wt::WLabel;
    ui.m_label2 = new Wt::WLabel;
    ui.m_label3 = new Wt::WLabel;
    //ui.m_chart = new Wt::Chart::WCartesianChart;

    this->addWidget(ui.m_label1);
    new Wt::WBreak(this);
    this->addWidget(ui.m_label2);
    new Wt::WBreak(this);
    this->addWidget(ui.m_label3);
    //new Wt::WBreak(this);
    //this->addWidget(ui.m_chart);

    ui.m_label1->setText("A: ? seconds, ? %");
    ui.m_label2->setText("B: ? seconds, ? %");
    ui.m_label3->setText("C: ? seconds, ? %");
    //ui.m_chart->setTitle("Choices in time");
    //ui.m_chart->setMinimumSize(400,400);
  }
}

///Send the new selected radio button's index
void ribi::ToolTimePoll::WtTimePollMainDialog::OnChangeIndex()
{
  ToolTimePoll::Data::GetInstance()->SetIndex(ui.m_group->selectedButtonIndex());
  WtServerPusher::GetInstance()->Post();
}

void ribi::ToolTimePoll::WtTimePollMainDialog::OnServerPush()
{
  //Only index has changed
  Data * const data = ToolTimePoll::Data::GetInstance();
  ui.m_group->setSelectedButtonIndex(data->GetIndex());
}

void ribi::ToolTimePoll::WtTimePollMainDialog::OnTimedServerPush()
{
  Data * const data = ToolTimePoll::Data::GetInstance();
  //Times have changed
  const std::vector<double> fractions = data->GetFractions();
  const std::vector<double> times = data->GetTimes();

  assert(fractions.size() == 3);
  assert(times.size() == 3);
  assert(ui.m_group);
  assert(ui.m_label1);
  assert(ui.m_label2);
  assert(ui.m_label3);

  ui.m_label1->setText(
    "A: "
    + boost::lexical_cast<std::string>(
        boost::numeric_cast<int>(
          times[0]))
    + " seconds, "
    + boost::lexical_cast<std::string>(
        boost::numeric_cast<int>(
          fractions[0] * 100.0))
    + "%"
    );
  ui.m_label2->setText(
    "B: "
    + boost::lexical_cast<std::string>(
        boost::numeric_cast<int>(
          times[1]))
    + " seconds, "
    + boost::lexical_cast<std::string>(
        boost::numeric_cast<int>(
          fractions[1] * 100.0))
    + "%"
    );
  ui.m_label3->setText(
    "C: "
    + boost::lexical_cast<std::string>(
        boost::numeric_cast<int>(
          times[2]))
    + " seconds, "
    + boost::lexical_cast<std::string>(
      boost::numeric_cast<int>(
        fractions[2] * 100.0))
    + "%"
    );
}

 

 

 

 

 

./ToolTimePoll/wttimepollmenudialog.h

 

//---------------------------------------------------------------------------
/*
TimePoll, time polling server
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTimePoll.htm
//---------------------------------------------------------------------------
#ifndef TIMEPOLLWTMENUDIALOG_H
#define TIMEPOLLWTMENUDIALOG_H

#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <Wt/WContainerWidget>
#pragma GCC diagnostic pop

namespace ribi {
namespace ToolTimePoll {

struct WtTimePollMenuDialog : public Wt::WContainerWidget
{
  WtTimePollMenuDialog();
  private:
  void CheckResources();
  Wt::WWidget * CreateNewAboutDialog();
  Wt::WWidget * CreateNewMainDialog() const;
  Wt::WWidget * CreateNewWelcomeDialog() const;
};

} //~namespace ToolTimePoll

} //~namespace ribi

#endif // TIMEPOLLWTMENUDIALOG_H

 

 

 

 

 

./ToolTimePoll/wttimepollmenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TimePoll, time polling server
Copyright (C) 2011-2015 Richel Bilderbeek

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
//---------------------------------------------------------------------------
//From http://www.richelbilderbeek.nl/ToolTimePoll.htm
//---------------------------------------------------------------------------
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Weffc++"
#pragma GCC diagnostic ignored "-Wunused-but-set-parameter"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WLabel>
#include <Wt/WStackedWidget>
#include <Wt/WMenu>
#include <Wt/WMenuItem>

#include "timepollmenudialog.h"
#include "wtaboutdialog.h"
#include "wtautoconfig.h"
#include "wtserverpusher.h"
#include "wtserverpusherclient.h"
#include "wttimedserverpusher.h"
#include "wttimedserverpusherclient.h"
#include "wttimepollmaindialog.h"
#include "wttimepollmenudialog.h"
#pragma GCC diagnostic pop

ribi::ToolTimePoll::WtTimePollMenuDialog::WtTimePollMenuDialog()
{
  this->setContentAlignment(Wt::AlignCenter);
  {
    Wt::WLabel * const title = new Wt::WLabel("TimePoll");
    title->setStyleClass("title");
    this->addWidget(title);
  }
  //Menu
  {
    Wt::WStackedWidget * const contents = new Wt::WStackedWidget;
    Wt::WMenu * const menu = new Wt::WMenu(contents,Wt::Horizontal);
    //Using CSS styleclass is the best (only?) way to display the menu well
    menu->setStyleClass("menu");
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "Welcome",
        CreateNewWelcomeDialog());
      menu->addItem(item);
    }
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "Start",
        CreateNewMainDialog());
      menu->addItem(item);
    }
    {
      Wt::WMenuItem * const item = new Wt::WMenuItem(
        "About",
        CreateNewAboutDialog());
      menu->addItem(item);
    }
    //Display menu on top
    this->addWidget(menu);
    this->addWidget(new Wt::WBreak);
    //Display contents below menu
    this->addWidget(contents);
  }
}

Wt::WWidget * ribi::ToolTimePoll::WtTimePollMenuDialog::CreateNewAboutDialog()
{
  About a = TimePollMenuDialog::GetAbout();
  a.AddLibrary("WtAutoConfig version: " + WtAutoConfig::GetVersion());
  a.AddLibrary("WtServerPusher version: " + WtServerPusher::GetVersion());
  a.AddLibrary("WtServerPusherClient version: " + WtServerPusherClient::GetVersion());
  a.AddLibrary("WtTimedServerPusher version: " + WtTimedServerPusher::GetVersion());
  a.AddLibrary("WtTimedServerPusherClient version: " + WtTimedServerPusherClient::GetVersion());
  WtAboutDialog * const d = new WtAboutDialog(a,false);
  assert(d);
  return d;
}

Wt::WWidget * ribi::ToolTimePoll::WtTimePollMenuDialog::CreateNewMainDialog() const
{
  WtTimePollMainDialog * const d = new WtTimePollMainDialog;
  assert(d);
  return d;
}

Wt::WWidget * ribi::ToolTimePoll::WtTimePollMenuDialog::CreateNewWelcomeDialog() const
{
  Wt::WContainerWidget * dialog = new Wt::WContainerWidget;
  dialog->setContentAlignment(Wt::AlignCenter);
  dialog->addWidget(new Wt::WBreak);
  new Wt::WLabel("Welcome to TimePoll",dialog);
  new Wt::WBreak(dialog);
  new Wt::WBreak(dialog);
  new Wt::WLabel("TimePoll demonstrates how to view the same changing info",dialog);
  new Wt::WBreak(dialog);
  new Wt::WLabel("from different browsers and/or computers",dialog);
  return dialog;
}

 

 

 

 

 

./ToolTimePoll/helgrind.sh

 

#!/bin/sh
valgrind --tool=helgrind --log-file=helgrind.txt ../ToolTimePoll-build-desktop/./ToolTimePoll

 

 

 

 

 

./ToolTimePoll/zip.sh

 

#!/bin/sh
#zip packs all the files to port into a single .zip file,
#minicking the same folder structure
#Folder structure
# *
#   * Classes
#     * CppAbout
#     * CppStopwatch
#     * CppWtAboutDialog
#     * CppWtAutoConfig
#     * CppWtServerPusher
#     * CppWtTimedServerPusher
#   * Tools
#    * ToolTimePoll

echo "Removing old user information"
rm copy.txt
rm tmp.txt
rm ToolTimePoll.pro.user

echo "Mimicking file structure"
mkdir temp_zip
mkdir temp_zip/Classes
mkdir temp_zip/Classes/CppAbout
mkdir temp_zip/Classes/CppStopwatch
mkdir temp_zip/Classes/CppWtAboutDialog
mkdir temp_zip/Classes/CppWtAutoConfig
mkdir temp_zip/Classes/CppWtServerPusher
mkdir temp_zip/Classes/CppWtTimedServerPusher

mkdir temp_zip/Tools
mkdir temp_zip/Tools/ToolTimePoll

echo "Copying files"
cp ../../Classes/CppAbout/*.* temp_zip/Classes/CppAbout
cp ../../Classes/CppStopwatch/*.* temp_zip/Classes/CppStopwatch
cp ../../Classes/CppWtAboutDialog/*.* temp_zip/Classes/CppWtAboutDialog
cp ../../Classes/CppWtAutoConfig/*.* temp_zip/Classes/CppWtAutoConfig
cp ../../Classes/CppWtServerPusher/*.* temp_zip/Classes/CppWtServerPusher
cp ../../Classes/CppWtTimedServerPusher/*.* temp_zip/Classes/CppWtTimedServerPusher

cp ../../Tools/ToolTimePoll/*.* temp_zip/Tools/ToolTimePoll



FILENAME=ToolTimePollSource_5_0
ZIP_FILENAME=$FILENAME".zip"

echo "Remove previous zip"
rm $ZIP_FILENAME

#echo "Compressing files"
cd temp_zip
zip -r $FILENAME Classes
#zip -r $FILENAME Games
#zip -r $FILENAME Libraries
#zip -r $FILENAME Projects
zip -r $FILENAME Tools
cd ..
cp "temp_zip/"$ZIP_FILENAME $ZIP_FILENAME

echo "Cleaning up"

#Classes
rm temp_zip/Classes/CppAbout/*.*
rm temp_zip/Classes/CppStopwatch/*.*
rm temp_zip/Classes/CppWtAboutDialog/*.*
rm temp_zip/Classes/CppWtAutoConfig/*.*
rm temp_zip/Classes/CppWtServerPusher/*.*
rm temp_zip/Classes/CppWtTimedServerPusher/*.*
rmdir temp_zip/Classes/CppAbout
rmdir temp_zip/Classes/CppStopwatch
rmdir temp_zip/Classes/CppWtAboutDialog
rmdir temp_zip/Classes/CppWtAutoConfig
rmdir temp_zip/Classes/CppWtServerPusher
rmdir temp_zip/Classes/CppWtTimedServerPusher
rmdir temp_zip/Classes

#Tools
rm temp_zip/Tools/ToolTimePoll/*.*
rmdir temp_zip/Tools/ToolTimePoll
rmdir temp_zip/Tools
rm temp_zip/*.*
rmdir temp_zip
echo "Done"

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict

This page has been created by the tool CodeToHtml