Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) TestSelectFileDialog source code (version 1.1)

 

TestSelectFileDialog source code (version 1.1).

 

 

 

 

 

Technical facts

 

Application type(s)

Operating system(s) or programming environment(s)

IDE(s):

Project type:

C++ standard:

Compiler(s):

Libraries used:

 

 

 

 

 

Qt project file: ToolTestSelectFileDialogWebsite.pro

 

#-------------------------------------------------
#
# Project created by QtCreator 2011-07-01T12:01:36
#
#-------------------------------------------------
QT       += core
QT       -= gui
LIBS += -lwt -lwthttp -lboost_program_options
TARGET = ToolTestSelectFileDialog
CONFIG   += console
CONFIG   -= app_bundle
TEMPLATE = app

INCLUDEPATH += \
    ../../Classes/CppAbout \
    ../../Classes/CppCopy_if \
    ../../Classes/CppTrace \
    ../../Classes/CppWtAboutDialog \
    ../../Classes/CppWtAutoConfig \
    ../../Classes/CppWtSelectFileDialog

SOURCES += \
    wtmain.cpp \
    ../../Classes/CppAbout/about.cpp \
    ../../Classes/CppWtAboutDialog/wtaboutdialog.cpp \
    ../../Classes/CppWtAutoConfig/wtautoconfig.cpp \
    ../../Classes/CppWtSelectFileDialog/wtselectfiledialog.cpp \
    wttestselectfiledialogmenudialog.cpp \
    wttestselectfiledialogmaindialog.cpp

HEADERS += \
    ../../Classes/CppAbout/about.h \
    ../../Classes/CppWtAboutDialog/wtaboutdialog.h \
    ../../Classes/CppWtAutoConfig/wtautoconfig.h \
    ../../Classes/CppWtSelectFileDialog/wtselectfiledialog.h \
    wttestselectfiledialogmenudialog.h \
    wttestselectfiledialogmaindialog.h \
    ../../Classes/CppCopy_if/copy_if.h \
    ../../Classes/CppTrace/trace.h

RESOURCES += \
    ToolTestSelectFileDialog.qrc

 

 

 

 

 

wtmain.cpp

 

//---------------------------------------------------------------------------
/*
TestSelectFileDialog, tool to test the SelectFileDialog class
Copyright (C) 2011 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/ToolTestSelectFileDialog.htm
//---------------------------------------------------------------------------
#include <boost/filesystem.hpp>
//---------------------------------------------------------------------------
#include <Wt/WApplication>
#include <Wt/WEnvironment>
//---------------------------------------------------------------------------
#include "wtautoconfig.h"
#include "wtselectfiledialog.h"
#include "wttestselectfiledialogmenudialog.h"
//---------------------------------------------------------------------------
struct WtApplication : public Wt::WApplication
{
  WtApplication(const Wt::WEnvironment& env)
    : Wt::WApplication(env)
  {
    this->setTitle("TestSelectFileDialog");
    this->useStyleSheet("wt.css");
    root()->addWidget(new WtTestSelectFileDialogMenuDialog);
  }
};
//---------------------------------------------------------------------------
Wt::WApplication *createApplication(const Wt::WEnvironment& env)
{
  return new WtApplication(env);
}
//---------------------------------------------------------------------------
int main(int argc, char **argv)
{
  WtSelectFileDialog::SetPath(boost::filesystem::path(argv[0]).parent_path().string());
  WtAutoConfig a(argc,argv,createApplication);
  WtAutoConfig::SaveDefaultStylesheet();
  return a.Run();
}
//---------------------------------------------------------------------------

 

 

 

 

 

wttestselectfiledialogmaindialog.cpp

 

//---------------------------------------------------------------------------
/*
TestSelectFileDialog, tool to test the SelectFileDialog class
Copyright (C) 2011 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/ToolTestSelectFileDialog.htm
//---------------------------------------------------------------------------
#include <boost/foreach.hpp>
#include <boost/lexical_cast.hpp>
#include <boost/numeric/conversion/cast.hpp>
#include <boost/signals2.hpp>
//---------------------------------------------------------------------------
#include <Wt/WAnchor>
#include <Wt/WApplication>
#include <Wt/WBreak>
#include <Wt/WEnvironment>
#include <Wt/WGroupBox>
#include <Wt/WLabel>
#include <Wt/WPushButton>
#include <Wt/WFileResource>
//---------------------------------------------------------------------------
#include "wtaboutdialog.h"
#include "wttestselectfiledialogmaindialog.h"
#include "wtselectfiledialog.h"
//---------------------------------------------------------------------------
#include <QFile>
//---------------------------------------------------------------------------
WtTestSelectFileDialogMainDialog::WtTestSelectFileDialogMainDialog()
{
  {
    std::vector<std::string> v;
    v.push_back("ToolTestSelectFileDialogWelcome.png");
    BOOST_FOREACH(const std::string& s,v)
    {
      if (!(QFile::exists(s.c_str())))
      {
        QFile f( (std::string(":/images/") + s).c_str() );
        f.copy(s.c_str());
      }
      assert(QFile::exists(s.c_str()));
    }
  }

  Show();
}
//---------------------------------------------------------------------------
void WtTestSelectFileDialogMainDialog::OnSelect()
{
  ui.m_anchor->setText((std::string("Download ") + ui.m_dialog->GetSelectedFile()).c_str() );
  ui.m_anchor->setResource(new Wt::WFileResource(ui.m_dialog->GetSelectedFile(),ui.m_dialog->GetSelectedFile()));
}
//---------------------------------------------------------------------------
void WtTestSelectFileDialogMainDialog::Show()
{
  clear();
  setContentAlignment(Wt::AlignCenter);

  ui.m_anchor = new Wt::WAnchor;
  ui.m_dialog = new WtSelectFileDialog;

  this->addWidget(ui.m_dialog);
  this->addWidget(new Wt::WBreak);
  this->addWidget(ui.m_anchor);

  ui.m_dialog->m_signal_selected.connect(
    boost::bind(&WtTestSelectFileDialogMainDialog::OnSelect,this));
}
//---------------------------------------------------------------------------

 

 

 

 

 

wttestselectfiledialogmaindialog.h

 

//---------------------------------------------------------------------------
/*
TestSelectFileDialog, tool to test the SelectFileDialog class
Copyright (C) 2011 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/ToolTestSelectFileDialog.htm
//---------------------------------------------------------------------------
#ifndef WTTESTSELECTFILEDIALOGMAINDIALOG_H
#define WTTESTSELECTFILEDIALOGMAINDIALOG_H
//---------------------------------------------------------------------------
#include <vector>
#include <boost/shared_ptr.hpp>
//---------------------------------------------------------------------------
#include <Wt/WContainerWidget>
//---------------------------------------------------------------------------
namespace Wt { struct WAnchor; }
struct WtSelectFileDialog;
//---------------------------------------------------------------------------
struct WtTestSelectFileDialogMainDialog : public Wt::WContainerWidget
{
  WtTestSelectFileDialogMainDialog();

  private:

  ///OnSelect is called when a user selects a file
  void OnSelect();

  ///Show is called at startup
  void Show();

  ///The user interface of this class
  struct Ui
  {
    Ui() : m_anchor(0), m_dialog(0) {}
    Wt::WAnchor * m_anchor;
    WtSelectFileDialog * m_dialog;
  } ui;
};
//---------------------------------------------------------------------------
#endif // WTTESTSELECTFILEDIALOGMAINDIALOG_H

 

 

 

 

 

wttestselectfiledialogmenudialog.cpp

 

//---------------------------------------------------------------------------
/*
TestSelectFileDialog, tool to test the SelectFileDialog class
Copyright (C) 2011 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/ToolTestSelectFileDialog.htm
//---------------------------------------------------------------------------
#include <Wt/WBreak>
#include <Wt/WContainerWidget>
#include <Wt/WGroupBox>
#include <Wt/WImage>
#include <Wt/WLabel>
#include <Wt/WStackedWidget>
#include <Wt/WMenu>
#include <Wt/WMenuItem>
//---------------------------------------------------------------------------
#include "copy_if.h"
#include "trace.h"
#include "wtaboutdialog.h"
#include "wtautoconfig.h"
#include "wtselectfiledialog.h"
#include "wttestselectfiledialogmaindialog.h"
#include "wttestselectfiledialogmenudialog.h"
//---------------------------------------------------------------------------
WtTestSelectFileDialogMenuDialog::WtTestSelectFileDialogMenuDialog()
{
  this->setContentAlignment(Wt::AlignCenter);
  {
    Wt::WLabel * const title = new Wt::WLabel("TestSelectFileDialog");
    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 * WtTestSelectFileDialogMenuDialog::CreateNewAboutDialog() const
{
   About a(
    "Richel Bilderbeek",
    "TestSelectFileDialog",
    "tool to test the SelectFileDialog class",
    "the 15th of July 2011",
    "2011",
    "http://www.richelbilderbeek.nl/ToolTestSelectFileDialog.htm",
    GetVersion(),
    GetVersionHistory());

  a.AddLibrary("Copy_if version: " + Copy_if_version::GetVersion());
  a.AddLibrary("Trace version: " + Trace::GetVersion());
  a.AddLibrary("WtAutoConfig version: " + WtAutoConfig::GetVersion());
  a.AddLibrary("WtSelectFileDialog version: " + WtSelectFileDialog::GetVersion());
  WtAboutDialog * const d = new WtAboutDialog(a,false);
  assert(d);
  return d;
}
//---------------------------------------------------------------------------
Wt::WWidget * WtTestSelectFileDialogMenuDialog::CreateNewMainDialog() const
{
  WtTestSelectFileDialogMainDialog * const d
    = new WtTestSelectFileDialogMainDialog;
  assert(d);
  return d;
}
//---------------------------------------------------------------------------
Wt::WWidget * WtTestSelectFileDialogMenuDialog::CreateNewWelcomeDialog() const
{
  Wt::WContainerWidget * dialog = new Wt::WContainerWidget;
  dialog->setContentAlignment(Wt::AlignCenter);
  dialog->addWidget(new Wt::WBreak);
  new Wt::WLabel("Welcome to TestSelectFileDialog",dialog);
  new Wt::WBreak(dialog);
  new Wt::WBreak(dialog);
  new Wt::WLabel("TestSelectFileDialog tests the WtSelectFileDialog class:",dialog);
  new Wt::WBreak(dialog);
  new Wt::WBreak(dialog);
  Wt::WGroupBox * const box = new Wt::WGroupBox("Example",dialog);
  Wt::WImage * const image = new Wt::WImage("ToolTestSelectFileDialogWelcome.png");
  box->addWidget(image);
  return dialog;
}
//---------------------------------------------------------------------------
const std::string WtTestSelectFileDialogMenuDialog::GetVersion()
{
  return "1.1";
}
//---------------------------------------------------------------------------
const std::vector<std::string> WtTestSelectFileDialogMenuDialog::GetVersionHistory()
{
  std::vector<std::string> v;
  v.push_back("2011-07-01: Version 1.0: initial version");
  v.push_back("2011-07-15: Version 1.1: added downloading of selected files");
  return v;
}
//---------------------------------------------------------------------------

 

 

 

 

 

wttestselectfiledialogmenudialog.h

 

//---------------------------------------------------------------------------
/*
TestSelectFileDialog, tool to test the SelectFileDialog class
Copyright (C) 2011 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/ToolTestSelectFileDialog.htm
//---------------------------------------------------------------------------
#ifndef WTTESTSELECTFILEDIALOGMENUDIALOG_H
#define WTTESTSELECTFILEDIALOGMENUDIALOG_H
//---------------------------------------------------------------------------
#include <string>
#include <vector>
//---------------------------------------------------------------------------
#include <Wt/WContainerWidget>
//---------------------------------------------------------------------------
struct WtTestSelectFileDialogMenuDialog : public Wt::WContainerWidget
{
  WtTestSelectFileDialogMenuDialog();

  static const std::string GetVersion();
  static const std::vector<std::string> GetVersionHistory();

  private:
  Wt::WWidget * CreateNewAboutDialog() const;
  Wt::WWidget * CreateNewMainDialog() const;
  Wt::WWidget * CreateNewWelcomeDialog() const;
};
//---------------------------------------------------------------------------
#endif // WTTESTSELECTFILEDIALOGMENUDIALOG_H

 

 

 

 

 

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
#     * CppCopy_if
#     * CppTrace
#     * CppWtAboutDialog
#     * CppWtAutoConfig
#     * CppWtSelectFileDialog
#   * Tools
#    * ToolTestSelectFileDialog

echo "Converting DIA to PNG"
dia --filter=png ToolTestSelectFileDialogArchitecture.dia

echo "Removing previous user's information"
rm ToolTestSelectFileDialogDesktop.pro.user
rm ToolTestSelectFileDialogWebsite.pro.user

echo "Mimicking file structure"
mkdir temp_zip
mkdir temp_zip/Classes
mkdir temp_zip/Classes/CppAbout
mkdir temp_zip/Classes/CppCopy_if
mkdir temp_zip/Classes/CppTrace
mkdir temp_zip/Classes/CppWtAboutDialog
mkdir temp_zip/Classes/CppWtAutoConfig
mkdir temp_zip/Classes/CppWtSelectFileDialog
mkdir temp_zip/Tools
mkdir temp_zip/Tools/ToolTestSelectFileDialog

echo "Copying files"
cp ../../Classes/CppAbout/*.* temp_zip/Classes/CppAbout
cp ../../Classes/CppCopy_if/*.* temp_zip/Classes/CppCopy_if
cp ../../Classes/CppTrace/*.* temp_zip/Classes/CppTrace
cp ../../Classes/CppWtAboutDialog/*.* temp_zip/Classes/CppWtAboutDialog
cp ../../Classes/CppWtAutoConfig/*.* temp_zip/Classes/CppWtAutoConfig
cp ../../Classes/CppWtSelectFileDialog/*.* temp_zip/Classes/CppWtSelectFileDialog
cp ../../Tools/ToolTestSelectFileDialog/*.* temp_zip/Tools/ToolTestSelectFileDialog

FILENAME=ToolTestSelectFileDialogSource_1_1
ZIP_FILENAME=$FILENAME".zip"

echo "Remove previous zip"
rm $ZIP_FILENAME

#echo "Compressing files"
cd temp_zip
zip -r $FILENAME Classes
#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/CppCopy_if/*.*
rm temp_zip/Classes/CppTrace/*.*
rm temp_zip/Classes/CppWtAboutDialog/*.*
rm temp_zip/Classes/CppWtAutoConfig/*.*
rm temp_zip/Classes/CppWtSelectFileDialog/*.*
rmdir temp_zip/Classes/CppAbout
rmdir temp_zip/Classes/CppCopy_if
rmdir temp_zip/Classes/CppTrace
rmdir temp_zip/Classes/CppWtAboutDialog
rmdir temp_zip/Classes/CppWtAutoConfig
rmdir temp_zip/Classes/CppWtSelectFileDialog
rmdir temp_zip/Classes

#Tools
rm temp_zip/Tools/ToolTestSelectFileDialog/*.*
rmdir temp_zip/Tools/ToolTestSelectFileDialog
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