Mailinglist Archive: opensuse-packaging (220 mails)

< Previous Next >
[opensuse-packaging] Assuma: Packaging Error: Error in include File
  • From: "Sascha 'saigkill' Manns" <samannsml@xxxxxxxxxxxxx>
  • Date: Thu, 10 Sep 2009 14:30:45 +0200
  • Message-id: <200909101430.46636@xxxxxxxxxxxxxxxxxxx>
Hi Mates,

now i'm building Assuma.

Im getting:
In file included from include/assuma_helpbrowser.h:21,
from src/assuma_mainwindow.cpp:36:
build/ui_assuma_helpbrowser.h:39: error: ISO C++ forbids declaration of
'QWebView' with no type
build/ui_assuma_helpbrowser.h:39: error: expected ';' before '*' token
build/ui_assuma_helpbrowser.h: In member function 'void
Ui_AssumaHelpBrowser::setupUi(QDialog*)':
build/ui_assuma_helpbrowser.h:94: error: 'webView' was not declared in this
scope
build/ui_assuma_helpbrowser.h:94: error: expected type-specifier before
'QWebView'
build/ui_assuma_helpbrowser.h:94: error: expected ';' before 'QWebView'
make: *** [build/assuma_mainwindow.o] Error 1

But i don't find the Error. I've attatched assuma_helpbrowser.h and
assuma_mainwindow.cpp. TheRest of the Sourcecode can shown at:
http://assuma.svn.sourceforge.net/viewvc/assuma/tags/3.0/

Has anyone an Idea, how to fix this?
--
Sincerely yours

Sascha Manns
openSUSE Ambassador
openSUSE Marketing Team
openSUSE Build Service
Web: http://saschamanns.gulli.to
Blog: http://saigkill.wordpress.com

// Copyright (C) 2009 by Arnaud Dupuis
// a.dupuis@xxxxxxxxxxxxxxxx
// http://www.infinityperl.org
//
// 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, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

#include "ui_assuma_helpbrowser.h"
#include <QDialog>
#include <QUrl>
/*! \class AssumaHelpBrowser
* \brief Association Subscribers Manager's help browser.
*
* This class is the help browser for Association Subscribers Manager. It is
based on Webkit (QWebView) so it can display lots of content.
* This browser is a dialog, take this in consideration.
*/
class AssumaHelpBrowser : public QDialog, public Ui::AssumaHelpBrowser {
Q_OBJECT
public:
/*!
Constructs a new browser.
\param parent the parent widget.
*/
AssumaHelpBrowser(QWidget *parent=0) ;
public slots:
/*!
Set and load the url of the page to load.
\param url the url to load.
*/
void setUrl(const QUrl &);
};
// Copyright (C) 2009 by Arnaud Dupuis
// a.dupuis@xxxxxxxxxxxxxxxx
// http://www.infinityperl.org
//
// 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, write to the
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA

#include <QtGui>
#include <QDebug>

#include "assuma_mainwindow.h"
#include "adbhandler.h"
#include "oldxmlhandler.h"
#include "addonxmlhandler.h"
#include "assuma_addonengine.h"
#include "assuma_subsciberimporterdialog.h"
#include "postalcodehandler.h"
#include "assuma_maildialog.h"
#include "assuma_updatedialog.h"
#include "federationhandler.h"
#include "assuma_treewidgetitemeditordelegate.h"
#include "assuma_effect.h"
#include "assuma_helpbrowser.h"

#ifndef ASSUMA_DATADIR
#define ASSUMA_DATADIR "/usr/share/assuma"
#endif

#ifndef ASSUMA_DOCDIR
#define ASSUMA_DOCDIR "/usr/share/AssociationSubscribersManager/doc"
#endif

#ifndef ASSUMA_IMGDIR
#define ASSUMA_IMGDIR "/usr/share/AssociationSubscribersManager/images"
#endif

AssumaMainWindow::AssumaMainWindow(QWidget *parent) : QMainWindow(parent)
{
// Private variables
currentDatabase = "";
previousLanguage = "";
shouldCloseEditor = false;
shouldSavePostalCodes=false;
dontUpdateSubscribersList = false;

// QPixmap pixmap(":/images/splash.png");
QPixmap pixmap(":/images/splash3X.png");
splash = new QSplashScreen( pixmap, Qt::WindowStaysOnTopHint );
splash->show();
splash->repaint();

setSplashMessage("Creating user interface");

setupUi(this);
setWindowTitle("[*]");
treeWidget->setIconSize( QSize(32,32) );
imagesListWidget->setUniformItemSizes(true);
imagesListWidget->setLayoutMode( QListView::Batched );
// Connect actions
connect(actionAbout_Qt, SIGNAL(activated()), this, SLOT(aboutQt()) );
connect(configWidget, SIGNAL( configMessage( const QString & ,
AssumaConfigWidget::Severity ) ), this, SLOT( showPassiveMessage( const QString
& , AssumaConfigWidget::Severity) ) );
connect(configWidget, SIGNAL( languageChanged(const QString &) ), this,
SLOT( changeLanguage(const QString &) ) );

setSplashMessage("Restoring previous session");

readSettings();
editArea->hide();
pictureEdit->hide();
searchWidget->hide();
imagesListWidget->hide();
addImagesButton->hide();
configWidget->hide();
searchWidget->setTreeWidget(treeWidget);

// Set the item delegate
treeWidgetDelegate = new AssumaTreeWidgetItemEditorDelegate(treeWidget);
treeWidgetDelegate->setCoursesList( configWidget->getCoursesList() );
treeWidgetDelegate->setCoursesLessonsNumberData(
configWidget->getCoursesLessonsNumberData() );
treeWidget->setItemDelegate( treeWidgetDelegate );

setSplashMessage("Creating menus");

contextMenu = new QMenu(treeWidget);
contextMenu->addAction(action_Copy);
contextMenu->addAction(actionPaste);
contextMenu->addAction(actionAdd_a_subscriber);
contextMenu->addAction(actionEdit_subscriber);
contextMenu->addAction(actionRemove_subscriber);
contextMenu->addSeparator();

// Getting QTreeWidget header's name and map them with the column number
QTreeWidgetItem *header = treeWidget->headerItem();
for (int i = 0 ; i <= header->columnCount() ; i++ ){
columnMap.insert( header->text(i) , i );
}
searchWidget->setColumnMap( columnMap );
// postalCodeEdit->setInsertPolicy(QComboBox::InsertAlphabetically);
qWarning() << "[WARNING] AssumaMainWindow::AssumaMainWindow() : We have
to be sure that the AssumaConfigWidget::DataDir config token will actually
return something !";
postal_codes_filename =
configWidget->getConfigToken(AssumaConfigWidget::DataDir) + "/PostalCodes/" +
configWidget->getConfigToken(AssumaConfigWidget::Country) + ".cities.xml" ;
// qDebug() << "AssumaMainWindow -> loading postal codes files :" <<
postal_codes_filename;
setSplashMessage( "Loading postal codes/cities: " +
configWidget->getConfigToken(AssumaConfigWidget::Country) );
loadPostalCodes( postal_codes_filename );

addonEngine = new AssumaAddonEngine( configWidget->getConfigToken(
AssumaConfigWidget::DataDir ) + "/Addons" );
loadAddons();

setSplashMessage( "Loading federation: " +
configWidget->getConfigToken(AssumaConfigWidget::Federation) );
loadFederation(
configWidget->getConfigToken(AssumaConfigWidget::Federation) );

setSplashMessage( "Loading subscribers database: " + currentDatabase );
loadDatabase( currentDatabase );

// qDebug() << "AssumaMainWindow -> About to destroy the splashscreen";
splash->finish(this);

// Test effects
qApp->setEffectEnabled(Qt::UI_AnimateMenu, true);
qApp->setEffectEnabled(Qt::UI_AnimateCombo, true);
qApp->setEffectEnabled(Qt::UI_AnimateTooltip, true);
qApp->setEffectEnabled(Qt::UI_AnimateToolBox, true);

setActionBarToolTips();

// qDebug() << "AssumaMainWindow -> constructor finish";
}

void AssumaMainWindow::setActionBarToolTips(){
// Set tooltip for actions in the action bar.
action_New->setToolTip("<table><tr><td valign=\"middle\"><img
src=\":/images/images/filenew.png\" /></td><td valign=\"middle\">" + tr("Create
a new empty database.") + "</td></tr></table>");
action_Open->setToolTip("<table><tr><td valign=\"middle\"><img
src=\":/images/images/fileopen.png\" /></td><td valign=\"middle\">" + tr("Open
an existing database and load it.") + "</td></tr></table>");
action_Save->setToolTip("<table><tr><td valign=\"middle\"><img
src=\":/images/images/filesave.png\" /></td><td valign=\"middle\">" + tr("Save
the current database.") + "</td></tr></table>");
actionSave_as->setToolTip("<table><tr><td valign=\"middle\"><img
src=\":/images/images/filesaveas.png\" /></td><td valign=\"middle\">" +
tr("Save the current database and asks you for the place to save the database
to.") + "</td></tr></table>");
actionQuit->setToolTip("<table><tr><td valign=\"middle\"><img
src=\":/images/images/exit.png\" /></td><td valign=\"middle\">" + tr("Quit
Association Subscribers Manager.") + "</td></tr></table>");
action_Find->setToolTip("<table><tr><td valign=\"middle\"><img
src=\":/images/images/search_user.png\" /></td><td valign=\"middle\">" +
tr("Display a window which allow you to search your database for a
subscriber.") + "</td></tr></table>");
actionSettings->setToolTip("<table><tr><td valign=\"middle\"><img
src=\":/images/images/configure.png\" /></td><td valign=\"middle\">" +
tr("Display the settings window.") + "</td></tr></table>");
actionAdd_a_subscriber->setToolTip("<table><tr><td
valign=\"middle\"><img src=\":/images/images/add_user.png\" /></td><td
valign=\"middle\">" + tr("Add an empty subscriber to the current database.") +
"</td></tr></table>");
actionEdit_subscriber->setToolTip("<table><tr><td
valign=\"middle\"><img src=\":/images/images/edit_user.png\" /></td><td
valign=\"middle\">" + tr("Turn the right part of Association Subscribers
Manager to the edit mode, allowing you to modify data about the currently
selected subscriber.") + "</td></tr></table>");
actionRemove_subscriber->setToolTip("<table><tr><td
valign=\"middle\"><img src=\":/images/images/delete_user.png\" /></td><td
valign=\"middle\">" + tr("Remove selected subscriber(s) from the current
database. once the database is saved, this operation cannot be undone.") +
"</td></tr></table>");

actionImport_subscribers_from_another_database->setToolTip("<table><tr><td
valign=\"middle\"><img src=\":/images/images/databaseimporter_corner.png\"
/></td><td valign=\"middle\">" + tr("Display a new window which allow you to
import subscribers from another database into the current one.") +
"</td></tr></table>");
actionUpdate->setToolTip("<table><tr><td valign=\"middle\"><img
src=\":/images/images/update.png\" /></td><td valign=\"middle\">" + tr("Display
the auto-update window.") + "</td></tr></table>");
}

void AssumaMainWindow::on_treeWidget_itemSelectionChanged(){
if( treeWidget->topLevelItemCount() > 0 &&
treeWidget->selectedItems().size() > 0 ){
editSubscriberButton->setEnabled(true);
deleteSubscriberButton->setEnabled(true);
sendSummaryButton->setEnabled(true);
actionEdit_subscriber->setEnabled(true);
actionRemove_subscriber->setEnabled(true);
// action_Find->setEnabled(true);
action_Copy->setEnabled(true);
}
else{
if( actionEdit_subscriber->isChecked() )
actionEdit_subscriber->setChecked(false);
editSubscriberButton->setEnabled(false);
deleteSubscriberButton->setEnabled(false);
sendSummaryButton->setEnabled(false);
actionEdit_subscriber->setEnabled(false);
actionRemove_subscriber->setEnabled(false);
// action_Find->setEnabled(false);
action_Copy->setEnabled(false);
}
}

void AssumaMainWindow::setSplashMessage( const QString & mesg ){
if(splash){
splash->showMessage(mesg, Qt::AlignLeft|Qt::AlignBottom,
Qt::white);
splash->repaint();
}
}

void AssumaMainWindow::checkUpdatesOnStart(){
if(
configWidget->getConfigToken(AssumaConfigWidget::UpdatesOnStart).toInt() == 1 ){
AssumaUpdateDialog *dial = new AssumaUpdateDialog(this);
connect( dial, SIGNAL(updateFinished(bool)), this, SLOT(
finishUpdate(bool) ) );
this->setVisible(false);
dial->show();
dial->checkForUpdates();
}
}

void AssumaMainWindow::loadPostalCodes(const QString & pc_filename){
if( QFile::exists(pc_filename) ){
QFile file(pc_filename);
QXmlInputSource inputSource(&file);
QXmlSimpleReader reader;
PostalCodeHandler *handler = new PostalCodeHandler();
reader.setContentHandler(handler);
reader.setErrorHandler(handler);
reader.parse(inputSource);
pc_map = handler->getPostalCodes();
// postalCodeEdit->clear();
// postalCodeEdit->addItems( pc_map.values() );
// cityEdit->clear();
// cityEdit->addItems( pc_map.keys() );
if( treeWidgetDelegate )
treeWidgetDelegate->setPostCodesMap( pc_map );
QCompleter *completer = new QCompleter(pc_map.keys(), this);
completer->setCaseSensitivity(Qt::CaseInsensitive);
cityEdit->setCompleter(completer);
QCompleter *completer_pc = new QCompleter(pc_map.values(),
this);
completer_pc->setCaseSensitivity(Qt::CaseInsensitive);
postalCodeEdit->setCompleter(completer_pc);
}
else{
showPassiveMessage( tr("Postal codes/cities file
<strong>%1</strong> could not be load.<br>File not found.").arg(pc_filename),
AssumaPassivePopup::Critical );
}
}

void AssumaMainWindow::loadLanguageList( const QString & lp_list_file ){
QFile file( lp_list_file );
QString serializedLanguageList;
if (!file.open(QIODevice::ReadOnly | QIODevice::Text)){
showPassiveMessage( tr("The languages list could not be
load.<br>It is possibly caused by a bad configuration of the data directory
(see: Settings -> General -> Data directory)"), AssumaPassivePopup::Warning );
return ;
}
QTextStream in(&file);
in.setCodec("UTF-8");
while (!in.atEnd()) {
QString line = in.readLine();
if( ! line.startsWith("#") ){
// First we process the line to replace variables with
values :
line.replace(QString("%IMGDIR%"),
QString(ASSUMA_IMGDIR));
line.replace(QString("%DATADIR%"),
QString(ASSUMA_DATADIR));
// A line in the file is based on this template :
// Language name;Language icon;Translation file
QStringList tmp = line.split(";");
translation_equiv.insert( tmp.at(0) , tmp.at(2) );
serializedLanguageList.append( tmp.at(1) );
serializedLanguageList.append( "," );
serializedLanguageList.append( tmp.at(0) );
serializedLanguageList.append( ";" );
}
}
configWidget->setConfigToken( AssumaConfigWidget::LanguageList,
serializedLanguageList );
}

void AssumaMainWindow::loadAddons(){
QString pluginsDir = configWidget->getConfigToken(
AssumaConfigWidget::DataDir ) + "/Addons" ;
// qDebug() << "AssumaMainWindow::loadAddons() -> pluginDir =" <<
pluginsDir ;
foreach (QString addonName,
configWidget->getConfigToken(AssumaConfigWidget::ActivatedAddonList).split(";")
)
{
if(addonName != ""){
// qDebug() << "AssumaMainWindow::loadAddons() ->
instantiating addon:" << addonName;
addonEngine->instanciateAddon(addonName);
}
}
configWidget->setLoadedAddonsList( addonEngine->instanciatedAddons() );
}

void AssumaMainWindow::writePostalCodes( const QString & fileName){
// qDebug() << citiesToXml();
// qDebug() << "AssumaMainWindow::writePostalCodes(" << fileName << ") :
saving postal codes list.";
QFileInfo fi(fileName);
if( fi.isWritable() ){
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text))
return;
QTextStream out(&file);
out.setCodec("UTF-8");
out << citiesToXml() << "\n";
showPassiveMessage( tr("cities database saved as
<strong>%1</strong>").arg(fileName) );
}
else
showPassiveMessage( tr("cities database could not be save as
<strong>%1</strong><br>You don't have the permission to write this
file.").arg(fileName), AssumaPassivePopup::Critical );
}

QString AssumaMainWindow::citiesToXml() {
QString xml;
xml.append("<?xml version=\"1.0\" encoding=\"utf-8\"
standalone=\"yes\"?>\n<Cities version=\"2.0\">\n");
foreach(QString city, pc_map.keys()){
xml.append("\t<City name=\"") ; xml.append(city) ;
xml.append("\" pc=\""); xml.append( pc_map.value(city) ) ; xml.append("\"
/>\n");
}
xml.append( "</Cities>" );
return xml;
}

double AssumaMainWindow::licenseFeeByLabel(const QString & label){
foreach ( FederationLicenseFee * fee, licences_fees ){
if( fee->getName() == label )
return fee->getFee();
}
return 0.0;
}

double AssumaMainWindow::licenseFeeById(const QString & id){
foreach ( FederationLicenseFee * fee, licences_fees ){
if( fee->getId() == id )
return fee->getFee();
}
return 0.0;
}

QString AssumaMainWindow::licenseIdByName(const QString & name){
foreach ( FederationLicenseFee * fee, licences_fees ){
if( fee->getName() == name )
return fee->getId();
}
return QString("");
}

QString AssumaMainWindow::licenseNameById(const QString & id){
foreach ( FederationLicenseFee * fee, licences_fees ){
if( fee->getId() == id )
return fee->getName();
}
return QString("");
}

// int AssumaMainWindow::calculateDue( const QListWidgetItem *item ){
double AssumaMainWindow::calculateDue( const QTreeWidgetItem *item ){
// qDebug() << " **** ENTERING calculateDue()";
// Contribution fee = ( (courses fee) x (number of trimesters in a
year) ) + (licence cost) + (static cost)
//! \todo extensively test the calculateDue() method (check that
calculation are done the right way).
int course_fee = configWidget->getCourseFee(
activityComboBox->currentText(), lessonsNumberEdit->value() ).toInt();
// qDebug() << "AssumaMainWindow -> course_fee is " << course_fee;

int trimesters_count =
configWidget->getConfigToken(AssumaConfigWidget::TrimesterCount).toInt();
// qDebug() << "AssumaMainWindow -> trimesters_count is " <<
trimesters_count;

int static_cost =
configWidget->getConfigToken(AssumaConfigWidget::StaticCost).toInt();
// qDebug() << "AssumaMainWindow -> dues = " << course_fee << " * " <<
trimesters_count << " + " << static_cost;
double _license_fee = licenseFeeByLabel(item->text(
elementColumn(tr("LicenseLabel")) ));
//! \todo : see how to integrate the use of item's data instead of the
current mechanism (it is also possible to embed the licenseLabelComboBox's
index instead of duplicate informations)
// qDebug() << " /!\\ _license_fee is " << _license_fee << " and data
contained fee is " << item->data( elementColumn( tr("LicenseLabel") ),
AssumaMainWindow::FeeRole );
// double due = course_fee * trimesters_count + static_cost +
licences_fees.value( item->text( elementColumn(tr("LicenseLabel")) ) , 0 );
double due = course_fee * trimesters_count + static_cost + _license_fee;

// qDebug() << "AssumaMainWindow -> LicenseLabel column is " <<
elementColumn(tr("LicenseLabel")) << " and fees for" << item->text(
elementColumn(tr("LicenseLabel")) ) << "is " << _license_fee ;

// qDebug() << "AssumaMainWindow -> dues is " << course_fee << " * " <<
trimesters_count << " + " << static_cost << " + " << _license_fee << " = " <<
due;
return due;
}

void AssumaMainWindow::changeLanguage(const QString & lang){
if( lang != previousLanguage){
// qDebug() << "AssumaMainWindow -> we just received a
languageChanged(" << lang << ") signal.";
if( translator )
QCoreApplication::removeTranslator(translator);
translator = new QTranslator() ;
QString tr_file = translation_equiv.value( lang );
if( tr_file.isEmpty() )
tr_file = "i18n/assuma_en-en.qm";
translator->load( tr_file );
// if( lang == "Francais" )
// translator->load("i18n/assuma_fr-fr");
// else if( lang == "English" )
// translator->load("i18n/assuma_en-en");
// else if( lang == "Francais (FFEPGV)" )
// translator->load("i18n/assuma_fr-ffepgv");
// else if( lang == "Portuguese (Brazilian)" )
// translator->load("i18n/assuma_pt-BR");
QCoreApplication::installTranslator(translator);
previousLanguage = lang;
retranslateUi(this);
QString currencies = configWidget->getConfigToken(
AssumaConfigWidget::CurrenciesList );
QString currency = configWidget->getConfigToken(
AssumaConfigWidget::Currency );
configWidget->retranslateUi(configWidget);
searchWidget->retranslateUi(searchWidget);
configWidget->setConfigToken(
AssumaConfigWidget::CurrenciesList, currencies );
configWidget->setConfigToken( AssumaConfigWidget::Currency,
currency );
setActionBarToolTips();
}
}

QString AssumaMainWindow::processTemplate( const QString & original){
// We don't want to modify the original string (it's a const anyway),
so we works on a copy
QString template_string = original;
// Process non-item related variables
template_string.replace( QString("%ASSO_NAME%"),
configWidget->getConfigToken(AssumaConfigWidget::AssociationName) );
template_string.replace( QString("%CURRENCY%"),
configWidget->getConfigToken(AssumaConfigWidget::Currency) );
QTreeWidgetItem *item;
item = treeWidget->currentItem();
// If there is a current item, we now process all item's related
variables
if( item ){
template_string.replace( QString("%SUBSCRIBER_FIRSTNAME%"),
item->text( elementColumn( tr("FirstName") ) ) );
template_string.replace( QString("%SUBSCRIBER_LASTNAME%"),
item->text( elementColumn( tr("LastName") ) ) );
template_string.replace( QString("%SUBSCRIBER_MAIDENNAME%"),
item->text( elementColumn( tr("MaidenName") ) ) );
template_string.replace( QString("%SUBSCRIBER_BIRTHDATE%"),
item->text( elementColumn( tr("BirthDate") ) ) );
template_string.replace( QString("%SUBSCRIBER_ADDRESS%"),
item->text( elementColumn( tr("Address") ) ) );
template_string.replace( QString("%SUBSCRIBER_CITY%"),
item->text( elementColumn( tr("City") ) ) );
template_string.replace( QString("%SUBSCRIBER_POSTALCODE%"),
item->text( elementColumn( tr("PostalCode") ) ) );
template_string.replace( QString("%SUBSCRIBER_PHONENUMBER%"),
item->text( elementColumn( tr("PhoneNumber") ) ) );
template_string.replace( QString("%SUBSCRIBER_EMAIL%"),
item->text( elementColumn( tr("Email") ) ) );
template_string.replace( QString("%SUBSCRIBER_ACTIVITY%"),
item->text( elementColumn( tr("Activity") ) ) );
template_string.replace( QString("%SUBSCRIBER_LESSONSNUMBER%"),
item->text( elementColumn( tr("LessonsNumber") ) ) );
template_string.replace( QString("%SUBSCRIBER_DUES%"),
item->text( elementColumn( tr("Dues") ) ) );
template_string.replace( QString("%SUBSCRIBER_DUESSTATUS%"),
item->text( elementColumn( tr("DuesStatus") ) ) );
template_string.replace(
QString("%SUBSCRIBER_SUBSCRIPTIONDATE%"), item->text( elementColumn(
tr("SubscriptionDate") ) ) );
template_string.replace(
QString("%SUBSCRIBER_MEDICALCERTIFICATESTATUS%"), item->text( elementColumn(
tr("MedicalCertificateStatus") ) ) );
template_string.replace( QString("%SUBSCRIBER_LICENSENUMBER%"),
item->text( elementColumn( tr("LicenseNumber") ) ) );
template_string.replace( QString("%SUBSCRIBER_COMMENT%"),
item->text( elementColumn( tr("Comment") ) ) );
template_string.replace( QString("%SUBSCRIBER_PICTURE%"),
item->text( elementColumn( tr("Picture") ) ) );

}
return template_string;
}

void AssumaMainWindow::showPassiveMessage( const QString & str ){
// qDebug() << "AssumaMainWindow::showPassiveMessage( const QString & str
) called";
AssumaPassivePopup *pop = new AssumaPassivePopup(this);
pop->setText(str);
AssumaEffect *effect = new AssumaEffect(0,pop,
AssumaEffect::SLIDE_FROM_BOTTOM);
connect( pop, SIGNAL( closeButtonClicked() ), effect, SLOT(
reverseEffect() ) );
connect( effect, SIGNAL( AssumaEffectFinished() ), pop, SLOT( hide() )
);
if( isVisible() ){
connect( effect, SIGNAL( AssumaEffectFinished() ), pop, SLOT(
close() ) );
effect->setTimeBeforeReversing( pop->timeToShow() );
}
else
effect->setTimeBeforeReversing( pop->timeToShow() * 5 );
effect->doEffect();
}

void AssumaMainWindow::showPassiveMessage( const QString & str ,
AssumaConfigWidget::Severity sev ){
// qDebug() << "AssumaMainWindow::showPassiveMessage( const QString & str
, AssumaConfigWidget::Severity sev ) called";
AssumaPassivePopup *pop = new AssumaPassivePopup(this);
pop->setText(str);
if( sev == AssumaConfigWidget::Info)
pop->setPixmap( AssumaPassivePopup::Info );
if( sev == AssumaConfigWidget::Warning)
pop->setPixmap( AssumaPassivePopup::Warning );
if( sev == AssumaConfigWidget::Critical)
pop->setPixmap( AssumaPassivePopup::Critical );
AssumaEffect *effect = new AssumaEffect(0,pop,
AssumaEffect::SLIDE_FROM_BOTTOM);
connect( pop, SIGNAL( closeButtonClicked() ), effect, SLOT(
reverseEffect() ) );
connect( effect, SIGNAL( AssumaEffectFinished() ), pop, SLOT( hide() )
);
if( isVisible() ){
connect( effect, SIGNAL( AssumaEffectFinished() ), pop, SLOT(
close() ) );
effect->setTimeBeforeReversing( pop->timeToShow() );
}
else
effect->setTimeBeforeReversing( pop->timeToShow() * 5 );
effect->doEffect();
}

void AssumaMainWindow::showPassiveMessage( const QString & str , const QPixmap
& pix ){
// qDebug() << "AssumaMainWindow::showPassiveMessage( const QString & str
, const QPixmap & pix ) called";
AssumaPassivePopup *pop = new AssumaPassivePopup(this);
pop->setText(str);
pop->setPixmap( pix.scaled(32,32) );
AssumaEffect *effect = new AssumaEffect(0,pop,
AssumaEffect::SLIDE_FROM_BOTTOM);
connect( pop, SIGNAL( closeButtonClicked() ), effect, SLOT(
reverseEffect() ) );
connect( effect, SIGNAL( AssumaEffectFinished() ), pop, SLOT( hide() )
);
if( isVisible() ){
connect( effect, SIGNAL( AssumaEffectFinished() ), pop, SLOT(
close() ) );
effect->setTimeBeforeReversing( pop->timeToShow() );
}
else
effect->setTimeBeforeReversing( pop->timeToShow() * 5 );
effect->doEffect();
}

void AssumaMainWindow::showPassiveMessage( const QString & str ,
AssumaPassivePopup::Icon ico ){
// qDebug() << "AssumaMainWindow::showPassiveMessage( const QString & str
, AssumaPassivePopup::Icon ico ) called";
AssumaPassivePopup *pop = new AssumaPassivePopup(this);
pop->setText(str);
pop->setPixmap( ico );
AssumaEffect *effect = new AssumaEffect(0,pop,
AssumaEffect::SLIDE_FROM_BOTTOM);
connect( pop, SIGNAL( closeButtonClicked() ), effect, SLOT(
reverseEffect() ) );
connect( effect, SIGNAL( AssumaEffectFinished() ), pop, SLOT( hide() )
);
if( isVisible() ){
connect( effect, SIGNAL( AssumaEffectFinished() ), pop, SLOT(
close() ) );
effect->setTimeBeforeReversing( pop->timeToShow() );
}
else
effect->setTimeBeforeReversing( pop->timeToShow() * 5 );
effect->doEffect();
}

void AssumaMainWindow::on_treeWidget_customContextMenuRequested ( const QPoint
& pos ){
int currentColumn = treeWidget->columnAt( pos.x() );
bool showAllColumnsActions = false;
QTreeWidgetItem *it_b = treeWidget->itemAt(pos);
if( ! it_b ){
showAllColumnsActions = true;
}
QTreeWidgetItem *header = treeWidget->headerItem();
// qDebug() << "We are in the column: " << header->text(currentColumn);
while ( contextMenu->actions().last()->text() != "" )
contextMenu->removeAction(contextMenu->actions().last());
if( header->text(currentColumn) == tr("FirstName") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_FirstName_column ) ;
}
if( header->text(currentColumn) == tr("MaidenName") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_MaidenName_column ) ;
}
if( header->text(currentColumn) == tr("LastName") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_LastName_column ) ;
}
if( header->text(currentColumn) == tr("BirthDate") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_BirthDate_column ) ;
}
if( header->text(currentColumn) == tr("Address") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_Address_column ) ;
}
if( header->text(currentColumn) == tr("City") || showAllColumnsActions
){
contextMenu->addAction( actionShow_City_column ) ;
}
if( header->text(currentColumn) == tr("PostalCode") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_PostalCode_column ) ;
}
if( header->text(currentColumn) == tr("PhoneNumber") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_PhoneNumber_column ) ;
}
if( header->text(currentColumn) == tr("Email") || showAllColumnsActions
){
contextMenu->addAction( actionShow_Email_column ) ;
}
if( header->text(currentColumn) == tr("Activity") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_Activity_column ) ;
}
if( header->text(currentColumn) == tr("LessonsNumber") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_LessonsNumber_column ) ;
}
if( header->text(currentColumn) == tr("LicenseLabel") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_LicenseLabel_column ) ;
}
if( header->text(currentColumn) == tr("Dues") || showAllColumnsActions
){
contextMenu->addAction( actionShow_Dues_column ) ;
}
if( header->text(currentColumn) == tr("DuesStatus") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_DuesStatus_column ) ;
}
if( header->text(currentColumn) == tr("SubscriptionDate") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_SubscriptionDate_column ) ;
}
if( header->text(currentColumn) == tr("MedicalCertificateStatus") ||
showAllColumnsActions ){
contextMenu->addAction(
actionShow_MedicalCertificateStatus_column ) ;
}
if( header->text(currentColumn) == tr("LicenseNumber") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_LicenseNumber_column ) ;
}
if( header->text(currentColumn) == tr("Comment") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_Comment_column ) ;
}
if( header->text(currentColumn) == tr("Picture") ||
showAllColumnsActions ){
contextMenu->addAction( actionShow_Picture_column ) ;
}
contextMenu->popup( treeWidget->mapToGlobal(pos) );
}

void AssumaMainWindow::on_actionQuit_activated(){
// qDebug() << "AssumaMainWindow-> about to quit";
close();
}

void AssumaMainWindow::on_action_New_activated(){
// qDebug() << "AssumaMainWindow-> Clearing currentDatabase";
currentDatabase = "";
// qDebug() << "AssumaMainWindow-> Clearing treeWidget";
treeWidget->clear();
// qDebug() << "AssumaMainWindow-> New document is ready !";
setWindowTitle( QString("Association Subscribers Manager -
[%1][*]").arg(currentDatabase) );
setWindowModified(true);
}

void AssumaMainWindow::aboutQt()
{
QMessageBox::aboutQt(this);
}

void
AssumaMainWindow::on_actionImport_subscribers_from_another_database_activated(){
AssumaSubscriberImporterDialog *importer = new
AssumaSubscriberImporterDialog(this);
connect(importer,SIGNAL(importSubscribers( QList<QTreeWidgetItem*>*
)),this,SLOT(subscribersImported( QList<QTreeWidgetItem*>* )));
importer->show();
}

void AssumaMainWindow::on_action_Open_activated(){
QString fileName = QFileDialog::getOpenFileName(this, tr("Open
File"),".",tr("ADB database (*.adb);;Old XML database (*.xml)"));
if( fileName.size() > 0 ){
update();
// If the QTreeWidget is not empty clear it
if( treeWidget->topLevelItemCount() > 0 )
treeWidget->clear();
// Loading XML database
loadDatabase(fileName);
}
// qDebug() << "Database file (open) : " << currentDatabase ;
}

AssumaMailDialog* AssumaMainWindow::createMailDialog(){
AssumaMailDialog *dial = new AssumaMailDialog(this);
QStringList list;
QTreeWidgetItem *rootitem = treeWidget->invisibleRootItem();
for(int k=0;k<rootitem->childCount(); k++){
QTreeWidgetItem *it = rootitem->child(k);
if( it->text( elementColumn( tr("Email") ) ).size() > 5 )
list << it->text( elementColumn( tr("Email") ) );
}
list << configWidget->getConfigToken( AssumaConfigWidget::ContactsList
).split(";");
dial->setEmailList( list );
dial->setSender( configWidget->getConfigToken(
AssumaConfigWidget::Email ) );
dial->setSmtpServer( configWidget->getConfigToken(
AssumaConfigWidget::SmtpServer ) );
if( ! configWidget->getConfigToken( AssumaConfigWidget::SmtpLogin
).isEmpty() ){
dial->setAuth( configWidget->getConfigToken(
AssumaConfigWidget::SmtpLogin ), configWidget->getConfigToken(
AssumaConfigWidget::SmtpPassword ) );
}
return dial ;
}

void AssumaMainWindow::on_actionSend_a_newsletter_activated(){
AssumaMailDialog *dial = createMailDialog();
QTreeWidgetItem *rootitem = treeWidget->invisibleRootItem();
for(int k=0;k<rootitem->childCount(); k++){
QTreeWidgetItem *it = rootitem->child(k);
if( it->text( elementColumn( tr("Email") ) ).size() > 5 )
dial->addEmail( it->text( elementColumn( tr("Email") )
) );
}
QString body(tr("Hello,\n\n\n\nBest regards,\n%ASSO_NAME%"));
dial->setSubject( processTemplate( tr("[%ASSO_NAME%] Newsletter") ) );
dial->setBody( processTemplate(body) );
dial->show();
}

void AssumaMainWindow::on_actionSend_fee_reminder_activated(){
AssumaMailDialog *dial = createMailDialog();
QTreeWidgetItem *rootitem = treeWidget->invisibleRootItem();
for(int k=0;k<rootitem->childCount(); k++){
QTreeWidgetItem *it = rootitem->child(k);
if( it->text( elementColumn( tr("DuesStatus") ) ) == tr("Not
ok") && it->text( elementColumn( tr("Email") ) ).size() > 5 ){
dial->addEmail( it->text( elementColumn(tr("Email")) )
);
}
}
dial->setSubject( processTemplate( tr("[%ASSO_NAME%] Fee reminder") ) );
dial->setBody( processTemplate( tr("Hello,\n\nwe would like to remind
you that you still need to pay your fee to our association.\n\nBest
regards,\n%ASSO_NAME%") ) );
dial->show();
}

void AssumaMainWindow::on_actionSend_database_by_email_activated(){
on_action_Save_activated();
AssumaMailDialog *dial = createMailDialog();
foreach (QString to, configWidget->getConfigToken(
AssumaConfigWidget::ContactsList ).split(";") ){
dial->addEmail(to);
}
dial->setSubject( processTemplate( tr("[%ASSO_NAME%] Subscribers
database") ) );
dial->setBody( processTemplate( tr("Hello,\n\nplease find attached the
subscribers database.\n\nBest regards,\n%ASSO_NAME%") ) );
dial->addAttachement( currentDatabase );
dial->show();
}

void AssumaMainWindow::on_action_Print_activated(){
#ifndef QT_NO_PRINTER
QPrinter printer;
printer.setOrientation(QPrinter::Landscape);
printer.setPageMargins( 0.25, 0.5, 0.25, 0.5, QPrinter::Inch );
QPrintDialog *dialog = new QPrintDialog(&printer, this);
dialog->setWindowTitle(tr("Print Database"));
if (dialog->exec() != QDialog::Accepted)
return;
QTextDocument doc;
QString html = subscribersListToPrintableHtml();
doc.setHtml( html );
doc.print(&printer);
#endif
}

bool AssumaMainWindow::areFeesEquivalent( QString base, QString comp){
// qDebug() << "AssumaMainWindow::areFeesEquivalent(QString, QString) =>
base : " << base << " comp : " << comp;
// Trivial tests here (to speed up the tests) : if the 2 strings are
exactly the same => true and if they have not the same size => false
if ( base == comp ){
// qDebug() << "AssumaMainWindow::areFeesEquivalent(QString,
QString) : base == comp -> return true";
return true;
}
// else if( base.size() != comp.size() ){
// qDebug() << "AssumaMainWindow::areFeesEquivalent(QString,
QString) : have different sizes -> return false";
// return false;
// }

// Now we have to take care of the non trivial part : if the strings
have the same size but are not the same (they can be the same if the order is
not the same).
QStringList blist = base.split(";");
QStringList clist = comp.split(";");
/** "Tous les cours:1=80,2=150,3=200;Kendo:1=150,2=200" **/
for (int i = 0 ; i < blist.count(); ++i){
QStringList blist_fee = blist.at(i).split(":");
QString tmp = blist_fee.at(0) ;
tmp.append(":.*");
QRegExp rx( tmp );
//tmp.append(":.+$/");
//tmp.prepend("/^");
// qDebug() << "AssumaMainWindow::areFeesEquivalent(QString,
QString) : about to search for " << tmp << "in " << clist;
int pos = clist.indexOf( rx );
if( pos != -1 ){
// qDebug() <<
"AssumaMainWindow::areFeesEquivalent(QString, QString) : activity " <<
blist_fee.at(0) << " found in the clist at position " << pos;
// Woohoo ! We have found an activity ! now we have to
check the fees.
foreach( QString tmp_cfee ,
clist.at(pos).split(":").at(1).split(",") ){
// qDebug() <<
"AssumaMainWindow::areFeesEquivalent(QString, QString) : tmp_cfee ->" <<
tmp_cfee;
bool tmpOkToContinue = false;
foreach( QString tmp_bfee ,
blist_fee.at(1).split(",") ){
if( tmp_bfee == tmp_cfee ){
tmpOkToContinue = true;
break;
}
}
if( ! tmpOkToContinue ){
// qDebug() <<
"AssumaMainWindow::areFeesEquivalent(QString, QString) : One ore more fees were
not found in the list -> return false";
return false;
}
}
}
else{
// qDebug() <<
"AssumaMainWindow::areFeesEquivalent(QString, QString) : activity " <<
blist_fee.at(0) << " not found in the clist (pos=" << pos << ") -> return
false";
return false;
}
}
// If we get here it means we have passed all test and the fees are
equivalents, so...
// qDebug() << "AssumaMainWindow::areFeesEquivalent(QString, QString) :
fees look equivalent to me...";
return true;
}

// This method loads all federation related taxes (if any) and update the GUI.
void AssumaMainWindow::loadFederation(const QString& federationName){
QString fileName( configWidget->getConfigToken(
AssumaConfigWidget::DataDir ) + "/Federations/" + federationName +
".federation.xml" );
// qDebug() << "AssumaMainWindow::loadFederation(" << federationName << ")
: loading the following federation file : " << fileName;
if( QFile::exists(fileName) ){
// Load federation description file
QFile file(fileName);
QXmlInputSource inputSource(&file);
QXmlSimpleReader reader;
FederationHandler handler ;
reader.setContentHandler(&handler);
reader.setErrorHandler(&handler);
reader.parse(inputSource);
// TODO: We have to adapt code to the new FederationHandler !!
(use FederationLicenseFee instead of the current QString in a QMap).
// NOTE: this is done, but before everything is tested and
functionnal I will not remove this todo.
licences_fees.empty();
licences_fees = handler.getLicenceFees();
// foreach( FederationLicenseFee *key, tmp_fees.keys() ){
// qDebug() << "AssumaMainWindow::loadFederation(" <<
federationName << ") : inserting into licences_fees -> " << key << "=" <<
tmp_fees.value(key);
// licences_fees.insert( key , tmp_fees.value(key) );
// }
// Updating GUI.
for( int i=0; i < licenseLabelComboBox->count(); ++i ){
licenseLabelComboBox->removeItem(i);
}
QStringList labels_list;
foreach( FederationLicenseFee *key, licences_fees ){
licenseLabelComboBox->addItem( key->getName() );
licenseLabelComboBox->setItemData(
licenseLabelComboBox->count() - 1, key->getId(), AssumaMainWindow::IdRole );
licenseLabelComboBox->setItemData(
licenseLabelComboBox->count() - 1, key->getName(), AssumaMainWindow::NameRole
);
licenseLabelComboBox->setItemData(
licenseLabelComboBox->count() - 1, key->getFee(), AssumaMainWindow::FeeRole );
labels_list << key->getName();
}
// qDebug() << "AssumaMainWindow::loadFederation(" <<
federationName << ") : adding follwings items to the licenseLabelComboBox : "
<< labels_list;
if( treeWidgetDelegate )
treeWidgetDelegate->setLicenseLabelsList( labels_list );
currentFederation = federationName;
}
else
showPassiveMessage( tr("Federation %1 taxes file could not be
load.<br>It means that fee calculation cannot be done
correctly.").arg(federationName), AssumaPassivePopup::Critical );
// qDebug() << "AssumaMainWindow::loadFederation(" << federationName << ")
: finished";
}

void AssumaMainWindow::loadDatabase(const QString& fileName){
if( ! QFile::exists(fileName) ){
showPassiveMessage( tr("Database <strong>%1</strong> could not
be load.<br>File not found").arg(fileName), AssumaPassivePopup::Critical );
return;
}
QProgressDialog progress(tr("Please wait while loading subscibers
database..."), "Abort loading", 0, 4, this);
progress.setWindowModality(Qt::WindowModal);
treeWidget->clear();
progress.setWindowTitle(tr("Loading database..."));
progress.setMinimumDuration(0);
progress.setCancelButton( 0 );
progress.setValue(0);
this->update();
QCoreApplication::processEvents(QEventLoop::AllEvents);
dontUpdateSubscribersList=true;
if(fileName.endsWith(".adb")){
currentDatabase = fileName ;
// qDebug() << "AssumaMainWindow-> Openning " << fileName;
progress.setValue(1);
progress.setLabelText(tr("Opening database: %1").arg(fileName));
QCoreApplication::processEvents(QEventLoop::AllEvents);
QFile file(fileName);
// qDebug() << "AssumaMainWindow-> Creating QXmlInputSource";
QXmlInputSource inputSource(&file);
// qDebug() << "AssumaMainWindow-> Creating QXmlSimpleReader";
QXmlSimpleReader reader;
AdbHandler handler(treeWidget);
reader.setContentHandler(&handler);
reader.setErrorHandler(&handler);
progress.setLabelText(tr("Processing database..."));
progress.setValue(2);
progress.update();
QCoreApplication::processEvents(QEventLoop::AllEvents);
// qDebug() << "AssumaMainWindow-> parsing inputSource";
reader.parse(inputSource);
// qDebug() << "AssumaMainWindow-> inputSource parsed";
progress.setLabelText(tr("Now exploiting database's data..."));
progress.setValue(3);
QCoreApplication::processEvents(QEventLoop::AllEvents);
exploitData();
progress.setValue(4);
progress.setLabelText(tr("Now exploiting database's data...done
!"));
QCoreApplication::processEvents(QEventLoop::AllEvents);
setWindowTitle( QString("Association Subscribers Manager -
[%1][*]").arg(currentDatabase) );
// qDebug() << "AssumaMainWindow -> This file is saved with the
following courses list : \n" << handler.getCoursesList() << "\nAnd config
courses list is :\n" << configWidget->getConfigToken(
AssumaConfigWidget::CoursesList );
// qDebug() << "AssumaMainWindow -> are fees equivalent ? " <<
areFeesEquivalent(handler.getCoursesList(), configWidget->getConfigToken(
AssumaConfigWidget::CoursesList ) );
if( (handler.getCoursesList().size() > 0 && !
areFeesEquivalent(handler.getCoursesList(), configWidget->getConfigToken(
AssumaConfigWidget::CoursesList ) )) || handler.getStaticCost() !=
configWidget->getConfigToken( AssumaConfigWidget::StaticCost ) ||
handler.getTrimesterCount() != configWidget->getConfigToken(
AssumaConfigWidget::TrimesterCount ) ){
int ret = QMessageBox::question(this,tr("Association
Subscribers Manager"),tr("The database you just load was written with a
different set of settings (fees, static cost, etc.).\nDo you want to load this
database's settings ?"),QMessageBox::Yes|QMessageBox::No);
if( ret == QMessageBox::Yes){

configWidget->setConfigToken(AssumaConfigWidget::CoursesList,
handler.getCoursesList() );
activityComboBox->clear();
activityComboBox->addItems(
configWidget->getCoursesList() );

configWidget->setConfigToken(AssumaConfigWidget::StaticCost,
handler.getStaticCost() );

configWidget->setConfigToken(AssumaConfigWidget::TrimesterCount,
handler.getTrimesterCount() );
}

}
if( handler.getFederationName() !=
configWidget->getConfigToken( AssumaConfigWidget::Federation ) ){
QString federationFileName(
configWidget->getConfigToken( AssumaConfigWidget::DataDir ) + "/Federations/" +
handler.getFederationName() + ".federation.xml" );
if( QFile::exists( federationFileName ) ){
int ret =
QMessageBox::question(this,tr("Association Subscribers Manager"),tr("The
database you just load was written with a different federation file (%1 instead
of your current %2).\nDo you want to load the %1 federation file ?\n(This will
not change your settings, only load the federation file for this
session)").arg( handler.getFederationName() ).arg(
configWidget->getConfigToken( AssumaConfigWidget::Federation )
),QMessageBox::Yes|QMessageBox::No);
if( ret == QMessageBox::Yes){
loadFederation(
handler.getFederationName() );
}
}
else if( ! handler.getFederationName().isEmpty() )
showPassiveMessage( tr("<b>WARNING !</b> The
database you just load was written using the <u><b>%1</b></u> federation
conditions,<br><u>you do not have this federation file on this computer</u>
!<br>Continue the edition of this file will most likely leads to data
compromission.").arg(handler.getFederationName()), AssumaPassivePopup::Critical
);
}
}
else if(fileName.endsWith(".xml")){
currentDatabase = fileName;
QMessageBox::warning(this,tr("Association Subscribers
Manager"),tr("<html>You are loading an old version of the Association
Subscriber Manager database,\nyour subscribers will be imported in the current
view\nand you will have to save this database in the new format.\nThe new
database files ends with \".adb\" (stands for <b>A</b>ssociation subscribers
manager <b>D</b>ata<b>B</b>ase).</html>"));
// qDebug() << "AssumaMainWindow-> Openning " << fileName;
progress.setLabelText(tr("Opening database: %1").arg(fileName));
QFile file(fileName);
// qDebug() << "AssumaMainWindow-> Creating QXmlInputSource";
QXmlInputSource inputSource(&file);
progress.setValue(1);
QCoreApplication::processEvents(QEventLoop::AllEvents);
// qDebug() << "AssumaMainWindow-> Creating QXmlSimpleReader";
QXmlSimpleReader reader;
OldXmlHandler handler(treeWidget);
reader.setContentHandler(&handler);
reader.setErrorHandler(&handler);
progress.setValue(2);
QCoreApplication::processEvents(QEventLoop::AllEvents);
progress.setLabelText(tr("Processing database..."));
// qDebug() << "AssumaMainWindow-> parsing inputSource";
reader.parse(inputSource);
// qDebug() << "AssumaMainWindow-> inputSource parsed";
progress.setLabelText(tr("Now exploiting database's data..."));
progress.setValue(3);
QCoreApplication::processEvents(QEventLoop::AllEvents);
exploitData();
progress.setValue(4);
QCoreApplication::processEvents(QEventLoop::AllEvents);
setWindowTitle( QString("Association Subscribers Manager -
[%1][*]").arg(currentDatabase) );
currentDatabase = "";
}
dontUpdateSubscribersList=false;
treeWidget->sortItems( 0, Qt::AscendingOrder );
for( int i = 0; i < treeWidget->headerItem()->columnCount(); i++){
treeWidget->resizeColumnToContents(i);
}
setWindowModified(false);
showPassiveMessage( tr( "Database <strong>%1</strong> <br/>successfully
loaded." ).arg(currentDatabase) );
// qDebug() << "AssumaMainWindow -> Application directory path:" <<
QCoreApplication::applicationDirPath();
}

void AssumaMainWindow::exploitData(){
QTreeWidgetItem *rootitem = treeWidget->invisibleRootItem();
// storing those variables here will considerably speed up the
application and reduce memory usage
int dsc = elementColumn(tr("DuesStatus"));
int mcsc = elementColumn(tr("MedicalCertificateStatus"));
//int pc = elementColumn("Picture");
QIcon ok_icon = QIcon(":/images/images/button_ok.png");
QIcon nok_icon = QIcon(":/images/images/remove.png");

for(int k=0;k<rootitem->childCount(); k++){
QTreeWidgetItem *it = rootitem->child(k);
// Setting all items editable
it->setFlags(it->flags() | Qt::ItemIsEditable);
QPixmap pix = QPixmap( it->text(elementColumn(tr("Picture"))) );
if(!pix)
pix = QPixmap(":/images/images/user_default.png");
it->setIcon( 0, QIcon(pix) );
// Setting text and icon for DuesStatus column
if( it->text(dsc) == "1" ){
it->setIcon(dsc, ok_icon );
it->setText(dsc, tr("Ok") );
}
else{
it->setIcon(dsc, nok_icon );
it->setText(dsc, tr("Not ok") );
}
// Setting text and icon for MedicalCertificateStatus column
if( it->text(mcsc) == "1" ){
it->setIcon(mcsc, ok_icon );
it->setText(mcsc, tr("Ok") );
}
else{
it->setIcon(mcsc, nok_icon );
it->setText(mcsc, tr("Not ok") );
}
// Setting the license label if there is one (after parsing the
.adb file there is only an id here, but it can also contains a license name
from an old database)
QString license_label = licenseNameById( it->text(
elementColumn(tr("LicenseLabel")) ) );
// qDebug() << " **** AssumaMainWindow::exploitData -> try to
match a license id for " << it->text( elementColumn(tr("LicenseLabel")) ) << "
match is " << license_label;
if( license_label != "" ){
it->setData( elementColumn(tr("LicenseLabel")),
AssumaMainWindow::IdRole, it->text( elementColumn(tr("LicenseLabel")) ) );
it->setText( elementColumn(tr("LicenseLabel")),
license_label );
}
bool uSL_previous = dontUpdateSubscribersList;
dontUpdateSubscribersList=false;
for( int i=0; i < it->columnCount(); i++ )
on_treeWidget_itemChanged(it,i);
dontUpdateSubscribersList = uSL_previous;
}

for ( int i = 0; i < treeWidget->columnCount(); i++ ){
treeWidget->resizeColumnToContents(i);
}
}

void AssumaMainWindow::exploitItemData( QTreeWidgetItem *it ){
int dsc = elementColumn(tr("DuesStatus"));
int mcsc = elementColumn(tr("MedicalCertificateStatus"));
QIcon ok_icon = QIcon(":/images/images/button_ok.png");
QIcon nok_icon = QIcon(":/images/images/remove.png");
if( it->text(dsc) == "1" || it->text(dsc) == "Ok"){
it->setIcon(dsc, ok_icon );
it->setText(dsc, tr("Ok") );
}
else{
it->setIcon(dsc, nok_icon );
it->setText(dsc, tr("Not ok") );
}
// Setting text and icon for MedicalCertificateStatus column
if( it->text(mcsc) == "1" || it->text(mcsc) == "Ok" ){
it->setIcon(mcsc, ok_icon );
it->setText(mcsc, tr("Ok") );
}
else{
it->setIcon(mcsc, nok_icon );
it->setText(mcsc, tr("Not ok") );
}
// Setting the license label if there is one (after parsing the .adb
file there is only an id here, but it can also contains a license name from an
old database)
QString license_label = licenseNameById( it->text(
elementColumn(tr("LicenseLabel")) ) );
if( license_label != "" ){
it->setData( elementColumn(tr("LicenseLabel")),
AssumaMainWindow::IdRole, it->text( elementColumn(tr("LicenseLabel")) ) );
it->setText( elementColumn(tr("LicenseLabel")), license_label );
}
}

void AssumaMainWindow::on_action_Save_activated(){
if( currentDatabase.isEmpty() ){
on_actionSave_as_activated();
}
else{
if(writeDatabase(currentDatabase)){
// setWindowTitle( QString("Association Subscribers
Manager - [%1][*]").arg(currentDatabase) );
// treeWidget->setWindowModified(false);
setWindowModified(false);
showPassiveMessage( tr("database saved as
<strong>%1</strong>").arg(currentDatabase) );
}
else{
QFileInfo fi(currentDatabase);
if( ! fi.isWritable() )
showPassiveMessage( tr("database
<strong>%1</strong> could not be saved !<br>You don't have the permission to
write this file.").arg(currentDatabase), AssumaPassivePopup::Critical );
else
showPassiveMessage( tr("database
<strong>%1</strong> could not be saved !").arg(currentDatabase),
AssumaPassivePopup::Critical );
}
}
}

bool AssumaMainWindow::writeDatabase(const QString & fileName){
QFile file(fileName);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
return false;
}
QTextStream out(&file);
out.setCodec("UTF-8");
out << subscribersListToXml() << "\n";

// QFile filec( fileName + ".gz" );
// if (!filec.open(QIODevice::WriteOnly | QIODevice::Text))
// return;
// QDataStream outc(&filec);
// outc << qCompress( subscribersListToXml().toAscii(), 9 );

return true;
}

int AssumaMainWindow::priceToInt(QString & price){
// qDebug() << "AssumaMainWindow->priceToInt(const QString & price) :
price=" << price;
int pos = price.indexOf(" ");
if(pos != -1){
price.remove(pos,100);
// qDebug() << "AssumaMainWindow->priceToInt(const QString &
price) : returning=>\""<<price<<"\"";
return price.toInt();
}
else
return -1;
}


QString AssumaMainWindow::subscribersListToHtml(){
QTreeWidgetItem *rootitem = treeWidget->invisibleRootItem();
QStringList html;
html << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>\n";
html << "<html xmlns=\"http://www.w3.org/1999/xhtml\"; xml:lang=\"en\"
lang=\"en\">\n";
html << "<head>\n" ;
html << "<title>" <<
configWidget->getConfigToken(AssumaConfigWidget::AssociationName) << ": " <<
tr("Subscribers list") << "</title>\n";
html << "<meta http-equiv=\"Content-type\" content=\"text/html;
charset=utf-8\" />";
html << "<style type=\"text/css\"><!--\n";
html << "table.table { border-top: 1px solid black; border-bottom: 1px
solid black; border-left: 1px solid black;}\n";
html << ".table_cell { border-top: 1px solid black; border-right: 1px
solid black; text-align : center; } \n";
html << "th { border-right: 1px solid black;}\n";
html << ".table_row_header { background: #80acff;}\n";
html << ".table_row_odd { background: #a2d7ff;}\n";
html << ".table_row:hover, .table_row_odd:hover { background:
#a7bfd2;}\n";
html << "#info_box { border: 1px solid black;}\n";
html << ".box_title { position: relative; width: 100%; background:
#80acff; }\n";
html << " --></style>";
html << "</head>\n<body>\n";
html << "<div id=\"info_box\">\n";
html << "<div class=\"box_title\"><strong>" << tr("Association: ") <<
"</strong>" <<
configWidget->getConfigToken(AssumaConfigWidget::AssociationName) << "</div>\n";
html << "<strong>" << tr("Number of subscribers") << ": </strong>" <<
QString::number(rootitem->childCount()) << "<br/>\n";
html << "</div><br/>\n";
html << "<table class=\"table\" cellspacing=\"0\">\n";
QTreeWidgetItem *header = treeWidget->headerItem();
html << "<tr class=\"table_row_header\">\n";
for ( int j=0 ; j < header->columnCount() ; ++j ){
if(header->text(j) != tr("Picture"))
html << "<th>" << header->text(j) << "</th>";
}
html << "</th>\n";
bool isOdd = false;
for(int k=0;k<rootitem->childCount(); k++)
{
QTreeWidgetItem *it = rootitem->child(k);
if(isOdd){
html << "<tr class=\"table_row_odd\">" ;
isOdd = false;
}
else{
html << "<tr class=\"table_row\">" ;
isOdd = true;
}
for ( int j=0 ; j < it->columnCount() ; ++j ){
if(header->text(j) != tr("Picture"))
html << "<td class=\"table_cell\">" <<
it->text(j) << "</td>";
}
html << "</tr>\n";
}
html << "</table>\n</body>\n</html>\n";
return html.join("");
}

QString AssumaMainWindow::subscribersListToPrintableHtml(){
QTreeWidgetItem *rootitem = treeWidget->invisibleRootItem();
QStringList html;
html << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\"
\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>\n";
html << "<html xmlns=\"http://www.w3.org/1999/xhtml\"; xml:lang=\"en\"
lang=\"en\">\n";
html << "<head>\n" ;
html << "<title>" <<
configWidget->getConfigToken(AssumaConfigWidget::AssociationName) << ": " <<
tr("Subscribers list") << "</title>\n";
html << "<meta http-equiv=\"Content-type\" content=\"text/html;
charset=utf-8\" />";
html << "</head>\n<body>\n";
html << "<div>\n";
html << "<strong>" << tr("Association: ") << "</strong>" <<
configWidget->getConfigToken(AssumaConfigWidget::AssociationName) << "<br/>\n";
html << "<strong>" << tr("Number of subscribers") << ": </strong>" <<
QString::number(rootitem->childCount()) << "<br/>\n";
html << "</div><br/><font size=\"10px\">\n";
html << "<table cellspacing=\"0\" border=\"1\">\n";
QTreeWidgetItem *header = treeWidget->headerItem();
html << "<tr bgcolor=\"#80acff\">\n";
for ( int j=0 ; j < header->columnCount() ; ++j ){
if(header->text(j) != tr("Picture"))
html << "<th>" << header->text(j) << "</th>";
}
html << "</th>\n";
bool isOdd = false;
for(int k=0;k<rootitem->childCount(); k++)
{
QTreeWidgetItem *it = rootitem->child(k);
if(isOdd){
html << "<tr bgcolor=\"#a2d7ff\">" ;
isOdd = false;
}
else{
html << "<tr>" ;
isOdd = true;
}
for ( int j=0 ; j < it->columnCount() ; ++j ){
if(header->text(j) != tr("Picture"))
html << "<td align=\"center\"
valign=\"middle\">" << it->text(j) << "</td>";
}
html << "</tr>\n";
}
html << "</table>\n</font></body>\n</html>\n";
return html.join("");
}

QString AssumaMainWindow::subscribersListToXml(){
// int embedImages = QMessageBox::question( this, tr("Embed images ?"),
// tr("Association Subscribers Manager can embed
images (like subscribers pictures),<br>This will produce a bigger file but save
you the trouble to manage pictures separatly.<br><br><strong>Do you want to
embed all subscribers pictures ?</strong>"),
// QMessageBox::Yes|QMessageBox::No
// );
QProgressDialog progress(tr("Please wait while saving subscibers
database..."), "Abort", 0, treeWidget->topLevelItemCount(), this);
progress.setWindowModality(Qt::WindowModal);
progress.setWindowTitle(tr("Writing database..."));
progress.setMinimumDuration(0);
progress.setCancelButton( 0 );
progress.setValue(0);
QTreeWidgetItem *rootitem = treeWidget->invisibleRootItem();
QString xml = "<?xml version=\"1.0\" encoding=\"utf-8\"
standalone=\"yes\"?>\n<Assuma adbversion=\""+ASSUMA_DB_VERSION+"\"
itemcount=\"";
xml.append( QString::number(rootitem->childCount()) ); xml.append("\"
");
xml.append("courseslist=\"");xml.append(
configWidget->getConfigToken(AssumaConfigWidget::CoursesList) );xml.append("\"
");
xml.append("staticcost=\"");xml.append(
configWidget->getConfigToken(AssumaConfigWidget::StaticCost) );xml.append("\"
");
xml.append("trimestercount=\"");xml.append(
configWidget->getConfigToken(AssumaConfigWidget::TrimesterCount)
);xml.append("\" ");
xml.append("federation=\"");xml.append(
configWidget->getConfigToken(AssumaConfigWidget::Federation) );xml.append("\"
");
xml.append(">\n");
int progression = 1;
for(int k=0;k<rootitem->childCount(); k++)
{
QTreeWidgetItem *it = rootitem->child(k);
calculateDue(it);
xml.append("\t<Subscriber>\n");
xml.append("\t\t<LastName><![CDATA["); xml.append( it->text(
elementColumn(tr("LastName")) ) ); xml.append("]]></LastName>\n");
xml.append("\t\t<MaidenName><![CDATA["); xml.append( it->text(
elementColumn(tr("MaidenName")) ) ); xml.append("]]></MaidenName>\n");
xml.append("\t\t<FirstName><![CDATA["); xml.append( it->text(
elementColumn(tr("FirstName")) ) ); xml.append("]]></FirstName>\n");
xml.append("\t\t<BirthDate><![CDATA["); xml.append( it->text(
elementColumn(tr("BirthDate")) ) ); xml.append("]]></BirthDate>\n");
xml.append("\t\t<Address><![CDATA["); xml.append( it->text(
elementColumn(tr("Address")) ) ); xml.append("]]></Address>\n");
xml.append("\t\t<City><![CDATA["); xml.append( it->text(
elementColumn(tr("City")) ) ); xml.append("]]></City>\n");
xml.append("\t\t<PostalCode><![CDATA["); xml.append( it->text(
elementColumn(tr("PostalCode")) ) ); xml.append("]]></PostalCode>\n");
xml.append("\t\t<PhoneNumber><![CDATA["); xml.append( it->text(
elementColumn(tr("PhoneNumber")) ) ); xml.append("]]></PhoneNumber>\n");
xml.append("\t\t<Email><![CDATA["); xml.append( it->text(
elementColumn(tr("Email")) ) ); xml.append("]]></Email>\n");
xml.append("\t\t<Activity><![CDATA["); xml.append( it->text(
elementColumn(tr("Activity")) ) ); xml.append("]]></Activity>\n");
xml.append("\t\t<LessonsNumber><![CDATA["); xml.append(
it->text( elementColumn(tr("LessonsNumber")) ) );
xml.append("]]></LessonsNumber>\n");
if( ! it->data( elementColumn( tr("LicenseLabel") ),
AssumaMainWindow::IdRole ).toString().isEmpty() ){
xml.append("\t\t<LicenseLabel><![CDATA["); xml.append(
it->data( elementColumn( tr("LicenseLabel") ), AssumaMainWindow::IdRole
).toString() ); xml.append("]]></LicenseLabel>\n");
}
else{
xml.append("\t\t<LicenseLabel><![CDATA["); xml.append(
licenseIdByName( it->text( elementColumn( tr("LicenseLabel") ) )) );
xml.append("]]></LicenseLabel>\n");
}
//QString dues_str = it->text( elementColumn( tr("Dues") ) );
//qDebug() << "AssumaMainWindow::subscribersListToXml() :
dues_str=" << dues_str;
//int dues = priceToInt( dues_str );
//int dues = dues_str.toInt();
//qDebug() << "AssumaMainWindow::subscribersListToXml() : int
dues=\""<<dues<<"\"";
xml.append("\t\t<Dues><![CDATA["); xml.append( it->text(
elementColumn( tr("Dues") ) ) ); xml.append("]]></Dues>\n");
// qDebug() << "AssumaMainWindow::subscribersListToXml() : xml="
<< xml;
if( it->text( elementColumn(tr("DuesStatus")) ) == tr("Ok") ){

xml.append("\t\t<DuesStatus><![CDATA[1]]></DuesStatus>\n");
}
else{

xml.append("\t\t<DuesStatus><![CDATA[0]]></DuesStatus>\n");
}
xml.append("\t\t<SubscriptionDate><![CDATA["); xml.append(
it->text( elementColumn(tr("SubscriptionDate")) ) );
xml.append("]]></SubscriptionDate>\n");

if( it->text( elementColumn(tr("MedicalCertificateStatus")) )
== tr("Ok") ){

xml.append("\t\t<MedicalCertificateStatus><![CDATA[1]]></MedicalCertificateStatus>\n");
}
else{

xml.append("\t\t<MedicalCertificateStatus><![CDATA[0]]></MedicalCertificateStatus>\n");
}

xml.append("\t\t<LicenseNumber><![CDATA["); xml.append(
it->text( elementColumn(tr("LicenseNumber")) ) );
xml.append("]]></LicenseNumber>\n");
xml.append("\t\t<Comment><![CDATA["); xml.append( it->text(
elementColumn(tr("Comment")) ) ); xml.append("]]></Comment>\n");

xml.append("\t\t<Picture embed=\"0\"><![CDATA["); xml.append(
it->text( elementColumn(tr("Picture")) ) ); xml.append("]]></Picture>\n");
// if(embedImages == QMessageBox::No){
// xml.append("\t\t<Picture embed=\"0\"><![CDATA[");
xml.append( it->text( elementColumn(tr("Picture")) ) );
xml.append("]]></Picture>\n");
// }
// else{
// QPixmap pixmap( it->text( elementColumn(tr("Picture"))
) );
// QByteArray bytes;
// QBuffer buffer(&bytes);
// buffer.open(QIODevice::WriteOnly);
// pixmap.scaled(QSize(64,64),
Qt::KeepAspectRatio).save(&buffer, "PNG");
// xml.append("\t\t<Picture embed=\"1\"><![CDATA[\n");
// xml.append( bytes.toBase64() );
// xml.append("\n\t\t]]></Picture>\n");
// }
xml.append("\t</Subscriber>\n");
progress.setValue(progression);
progression++;
QCoreApplication::processEvents(QEventLoop::AllEvents);

}
xml.append("</Assuma>");
progress.setValue(treeWidget->topLevelItemCount());
return xml;
}

bool AssumaMainWindow::maybeSave(){
// qDebug() << "treeWidget->isWindowModified() = " <<
treeWidget->isWindowModified() << " and isWindowModified() = " <<
isWindowModified();
if( isWindowModified() ) {
QMessageBox::StandardButton ret;
ret = QMessageBox::warning(this, tr("Association Subscribers
Manager"),
tr("The current database has been modified.\n"
"Do you want to save your changes?"),
QMessageBox::Save | QMessageBox::Discard |
QMessageBox::Cancel);
if (ret == QMessageBox::Save){
on_action_Save_activated();
return true;
}
else if (ret == QMessageBox::Cancel)
return false;
}
if( shouldSavePostalCodes )
writePostalCodes(postal_codes_filename);
return true;
}

void AssumaMainWindow::closeEvent(QCloseEvent *event)
{
// qDebug() << "AssumaMainWindow-> Got a close event.";
if (maybeSave()) {
writeSettings();
addonEngine->destroyAllAddons();
event->accept();
} else {
event->ignore();
}
}

int AssumaMainWindow::elementColumn(const QString& element){
QTreeWidgetItem *header = treeWidget->headerItem();
for (int i = 0 ; i <= header->columnCount() ; i++ ){
if( element == header->text(i) )
return i;
}
return -1;
}

int AssumaMainWindow::elementColumn(const QTreeWidgetItem *header, const
QString& element){
for (int i = 0 ; i <= header->columnCount() ; i++ ){
if( element == header->text(i) )
return i;
}
return -1;
}

void AssumaMainWindow::on_editSubscriberButton_toggled(bool b){
if(b){
editArea->show();
textBrowser->hide();
pictureEdit->show();
pictureLabel->hide();
editSubscriberButton->setStyleSheet("background-color: rgb(255,
99, 99);border: 2px solid darkkhaki;border-radius: 3px;");
}
else{
on_treeWidget_currentItemChanged( treeWidget->currentItem(), 0
); // I often use this to refresh the textBrowser content.
editArea->hide();
textBrowser->show();
pictureEdit->hide();
pictureLabel->show();
editSubscriberButton->setStyleSheet("");
on_pictureEdit_toggled(false);
}
// setWindowTitle( QString("Association Subscribers Manager -
[%1][*]").arg(currentDatabase) );
// treeWidget->setWindowModified(true);
setWindowModified(true);
}

void AssumaMainWindow::on_actionSave_as_activated(){
QString path = currentDatabase;
if( path.isEmpty() ){
path =".";
}
QString fileName = QFileDialog::getSaveFileName(this, tr("Save
File"),path,tr("ADB database (*.adb)"));
if(fileName.size() > 0){
currentDatabase = fileName;
if( !currentDatabase.endsWith(".adb") )
currentDatabase.append(".adb");
on_action_Save_activated();
// setWindowTitle( QString("Association Subscribers Manager -
[%1][*]").arg(currentDatabase) );
}
// qDebug() << "AssumaMainWindow-> Database file (save as) : " <<
currentDatabase;
}

void AssumaMainWindow::updateSplitterSize(){
int tww = treeWidget->width();
int fw = frame->width();
// qDebug() << "AssumaMainWindow::updateSplitterSize() -> splitter sizes :
" << splitter->sizes() << " treeWidget width : " << tww << " frame width : " <<
fw;
splitter->setSizes( QList<int>()<< tww << fw );
}

void AssumaMainWindow::on_action_Find_toggled(bool visible){
if(visible){


AssumaEffect *tw_effect = new
AssumaEffect(0,treeWidget,AssumaEffect::SHRINK_VERTICALLY);
// qDebug() << "AssumaMainWindow::on_action_Find_toggled(bool
visible) -> searchWidget size : " << searchWidget->size() << " searchWidget
sizeHint : " << searchWidget->sizeHint() << " treeWidget size : " <<
treeWidget->size();
tw_effect->setVSizeDelta( searchWidget->size().height() + 2 );
tw_effect->setReversing(false);

searchWidget->move(0, (
treeWidget->pos().y()+treeWidget->height() ) );
AssumaEffect *effect = new
AssumaEffect(0,searchWidget,AssumaEffect::GROW_VERTICALLY);
effect->setReversing(false);
// connect( tw_effect, SIGNAL( AssumaEffectFinished() ), effect,
SLOT( doEffect() ) );


int tw_effect_size = 750;
if( searchWidget->size().width() >= 750 )
tw_effect_size = searchWidget->size().width();
if( tw_effect_size > treeWidget->size().width() ){
AssumaEffect *expand_effect = new
AssumaEffect(0,treeWidget,AssumaEffect::EXPAND_HORIZONTALLY);
expand_effect->setVSizeDelta( tw_effect_size -
treeWidget->size().width() );
expand_effect->setReversing(false);
connect( expand_effect, SIGNAL( AssumaEffectFinished()
), effect, SLOT( doEffect() ) );
connect( expand_effect, SIGNAL( AssumaEffectFinished()
), tw_effect, SLOT( doEffect() ) );
connect( expand_effect, SIGNAL(
AssumaEffectWasUpdated() ), this, SLOT( updateSplitterSize() ) );
expand_effect->doEffect();
}
else{
// qDebug() <<
"AssumaMainWindow::on_action_Find_toggled(bool visible) -> starting
GROW_VERTICALLY effect on searchWidget";
effect->doEffect();
// qDebug() <<
"AssumaMainWindow::on_action_Find_toggled(bool visible) -> starting
SHRINK_VERTICALLY effect on treeWidget";
tw_effect->doEffect();
}
searchWidget->setFocus();
}
else{
AssumaEffect *tw_effect = new
AssumaEffect(0,treeWidget,AssumaEffect::EXPAND_VERTICALLY);
tw_effect->setVSizeDelta( searchWidget->size().height() + 2 );
tw_effect->setReversing(false);
AssumaEffect *effect = new
AssumaEffect(0,searchWidget,AssumaEffect::SLIM_VERTICALLY);
effect->setReversing(false);
connect( effect, SIGNAL( AssumaEffectFinished() ),
searchWidget, SLOT( hide() ) );
// qDebug() << "AssumaMainWindow::on_action_Find_toggled(bool
visible) -> starting EXPAND_VERTICALLY effect on treeWidget";
tw_effect->doEffect();
// qDebug() << "AssumaMainWindow::on_action_Find_toggled(bool
visible) -> starting SLIM_VERTICALLY effect on searchWidget";
effect->doEffect();
// searchWidget->hide();
}
}

void AssumaMainWindow::readSettings(){
// qDebug() << "AssumaMainWindow-> Reading settings";
QSettings settings("Infinity Perl","assuma");
restoreGeometry(settings.value("mw_geometry").toByteArray());

splitter->restoreState(settings.value("splitter_geometry").toByteArray());

// Restoring settings from the configuration widget
configWidget->setConfigToken(AssumaConfigWidget::TrimesterCount,
settings.value("configTrimesterCount",QString::number(3)).toString());
configWidget->setConfigToken(AssumaConfigWidget::StaticCost,
settings.value("configStaticCost",QString::number(0)).toString());
configWidget->setConfigToken(AssumaConfigWidget::DataDir,
settings.value("configDataDir",QString(ASSUMA_DATADIR) + "/data").toString() );
// DataDir is set, this is all we need to load the list of available
languages.
loadLanguageList(
configWidget->getConfigToken(AssumaConfigWidget::DataDir).append("/langpack.lst")
);
// Getting the list of Federation files
QDir dataDir( configWidget->getConfigToken( AssumaConfigWidget::DataDir
)+"/Federations" );
QStringList filters;
QStringList federation_list;
filters << "*.federation.xml";
dataDir.setNameFilters(filters);
// qDebug() << "AssumaMainWindow -> federation files : " <<
dataDir.entryList();
foreach ( QString it, dataDir.entryList() ){
it.remove(".federation.xml");
federation_list << it;
}
configWidget->setConfigToken( AssumaConfigWidget::FederationList ,
federation_list.join(";") );
configWidget->setConfigToken(AssumaConfigWidget::Federation,
settings.value("configFederation","DefaultNull").toString());
configWidget->setConfigToken(AssumaConfigWidget::UpdateServer,
settings.value("configUpdateServer","http://assuma.sourceforge.net";).toString());
configWidget->setConfigToken(AssumaConfigWidget::UpdatesOnStart,
settings.value("configUpdatesOnStart",QString::number(1)).toString());
configWidget->setConfigToken(AssumaConfigWidget::ContactsList,
settings.value("configContactsList","").toString());
configWidget->setConfigToken(AssumaConfigWidget::CoursesList,
settings.value("configCoursesList","").toString());
if( configWidget->getConfigToken( AssumaConfigWidget::CoursesList ) ==
"" )
configWidget->addActivity( tr("All courses") );
configWidget->setConfigToken(AssumaConfigWidget::Language,
settings.value("configLanguage","English").toString());
changeLanguage( configWidget->getConfigToken(
AssumaConfigWidget::Language ) );
configWidget->setConfigToken(AssumaConfigWidget::Encoding,
settings.value("configEncoding","UTF-8").toString());
configWidget->setConfigToken(AssumaConfigWidget::AssociationName,
settings.value("configAssociationName","MyAssociation").toString());
configWidget->setConfigToken(AssumaConfigWidget::Email,
settings.value("configEmail","Owner@xxxxxxxxxxxxxxxxx").toString());
configWidget->setConfigToken(AssumaConfigWidget::SmtpServer,
settings.value("configSmtpServer","localhost").toString());
configWidget->setConfigToken(AssumaConfigWidget::SmtpLogin,
settings.value("configSmtpLogin","").toString());
configWidget->setConfigToken(AssumaConfigWidget::SmtpPassword,
settings.value("configSmtpPassword","").toString());
configWidget->setConfigToken(AssumaConfigWidget::ProxyServer,
settings.value("configProxyServer","").toString());
configWidget->setConfigToken(AssumaConfigWidget::ProxyLogin,
settings.value("configProxyLogin","").toString());
configWidget->setConfigToken(AssumaConfigWidget::ProxyPassword,
settings.value("configProxyPassword","").toString());
configWidget->setConfigToken(AssumaConfigWidget::ProxyEnabled,
settings.value("configProxyEnabled","0").toString());
configWidget->setConfigToken(AssumaConfigWidget::Country,
settings.value("configCountry","SmallTest").toString());
// We have to update the addons list before setting the list of
activated ones or else the list being empty we lose settings
configWidget->updateAddonList();
configWidget->setConfigToken(AssumaConfigWidget::ActivatedAddonList,
settings.value("configActivatedAddonList","").toString());
configWidget->setConfigToken( AssumaConfigWidget::CurrenciesList,
settings.value("configCurrenciesList",QString::fromUtf8("Baht (฿);Dollar
($);Dong (₫);Euro (\xe2\x82\xac);Hryvnia (₴);Real (R$);Won (₩);Pound
(\xc2\xa3);svensk krona (SEK);Yen (¥);Yuan (元)")).toString() );
configWidget->setConfigToken( AssumaConfigWidget::Currency,
settings.value( "configCurrency", QString::fromUtf8("Euro (€)") ).toString() );

QString arg_db;
foreach ( QString str, QCoreApplication::arguments() ){
if( QFile::exists(str) && str.endsWith(".adb") )
arg_db = str;
}
if(arg_db.isEmpty())
currentDatabase = settings.value("last_database","").toString()
;
else
currentDatabase = arg_db;

QStringList images =
settings.value("userDefinedAvatars",QStringList()).toStringList();
for (int k = 0; k < images.count(); ++k){
addAvatar( images.at(k) );
}

// Restoring column status
actionShow_FirstName_column->setChecked(
settings.value("showFirstNameColumn",true).toBool() );
actionShow_MaidenName_column->setChecked(
settings.value("showMaidenNameColumn",true).toBool() );
actionShow_LastName_column->setChecked(
settings.value("showLastNameColumn",true).toBool() );
actionShow_BirthDate_column->setChecked(
settings.value("showBirthDateColumn",true).toBool() );
actionShow_City_column->setChecked(
settings.value("showCityColumn",true).toBool() );
actionShow_PostalCode_column->setChecked(
settings.value("showPostalCodeColumn",true).toBool() );
actionShow_PhoneNumber_column->setChecked(
settings.value("showPhoneNumberColumn",true).toBool() );
actionShow_Email_column->setChecked(
settings.value("showEmailColumn",true).toBool() );
actionShow_Activity_column->setChecked(
settings.value("showActivityColumn",true).toBool() );
actionShow_LessonsNumber_column->setChecked(
settings.value("showLessonsNumberColumn",true).toBool() );
actionShow_LicenseLabel_column->setChecked(
settings.value("showLicenseLabelColumn",true).toBool() );
actionShow_Dues_column->setChecked(
settings.value("showDuesColumn",true).toBool() );
actionShow_DuesStatus_column->setChecked(
settings.value("showDuesStatusColumn",true).toBool() );
actionShow_SubscriptionDate_column->setChecked(
settings.value("showSubscriptionDateColumn",true).toBool() );
actionShow_MedicalCertificateStatus_column->setChecked(
settings.value("showMedicalCertificateStatusColumn",true).toBool() );
actionShow_LicenseNumber_column->setChecked(
settings.value("showLicenseNumberColumn",true).toBool() );
actionShow_Comment_column->setChecked(
settings.value("showCommentColumn",true).toBool() );
actionShow_Picture_column->setChecked(
settings.value("showPictureColumn",true).toBool() );

activityComboBox->clear();
activityComboBox->addItems( configWidget->getCoursesList() );
duesEdit->setSuffix( " "+configWidget->getConfigToken(
AssumaConfigWidget::Currency ) );
}

void AssumaMainWindow::writeSettings(){
// qDebug() << "AssumaMainWindow-> Writting settings";
QSettings settings("Infinity Perl","assuma");
settings.setValue("mw_geometry", saveGeometry());
settings.setValue("last_database",currentDatabase);
settings.setValue("splitter_geometry", splitter->saveState() );
QStringList images;
for( int k=0; k < imagesListWidget->count() ; ++k ){
QListWidgetItem *it = imagesListWidget->item(k);
// qDebug() << "AssumaMainWindow::writeSettings() : item -> " <<
it->text() ;
if( QFile::exists( it->text() ) ){
images << it->text();
}
}
settings.setValue("userDefinedAvatars",images);

// Saving settings from the configuration widget
settings.setValue("configTrimesterCount",
configWidget->getConfigToken(AssumaConfigWidget::TrimesterCount) );
settings.setValue("configStaticCost",
configWidget->getConfigToken(AssumaConfigWidget::StaticCost) );
settings.setValue("configFederation",
configWidget->getConfigToken(AssumaConfigWidget::Federation) );
settings.setValue("configUpdateServer",
configWidget->getConfigToken(AssumaConfigWidget::UpdateServer) );
settings.setValue("configUpdatesOnStart",
configWidget->getConfigToken(AssumaConfigWidget::UpdatesOnStart) );
settings.setValue("configContactsList",
configWidget->getConfigToken(AssumaConfigWidget::ContactsList) );
settings.setValue("configCoursesList",
configWidget->getConfigToken(AssumaConfigWidget::CoursesList) );
settings.setValue("configLanguage",
configWidget->getConfigToken(AssumaConfigWidget::Language) );
// qDebug() << "AssumaMainWindow::writeSettings() -> saved language is :"
<< configWidget->getConfigToken(AssumaConfigWidget::Language) ;
settings.setValue("configEncoding",
configWidget->getConfigToken(AssumaConfigWidget::Encoding) );
settings.setValue("configAssociationName",
configWidget->getConfigToken(AssumaConfigWidget::AssociationName) );
settings.setValue("configEmail",
configWidget->getConfigToken(AssumaConfigWidget::Email) );
settings.setValue("configSmtpServer",
configWidget->getConfigToken(AssumaConfigWidget::SmtpServer) );
settings.setValue("configSmtpLogin",
configWidget->getConfigToken(AssumaConfigWidget::SmtpLogin) );
settings.setValue("configSmtpPassword",
configWidget->getConfigToken(AssumaConfigWidget::SmtpPassword) );
settings.setValue("configProxyServer",
configWidget->getConfigToken(AssumaConfigWidget::ProxyServer) );
settings.setValue("configProxyLogin",
configWidget->getConfigToken(AssumaConfigWidget::ProxyLogin) );
settings.setValue("configProxyPassword",
configWidget->getConfigToken(AssumaConfigWidget::ProxyPassword) );
settings.setValue("configProxyEnabled",
configWidget->getConfigToken(AssumaConfigWidget::ProxyEnabled) );
settings.setValue("configDataDir",
configWidget->getConfigToken(AssumaConfigWidget::DataDir) );
settings.setValue("configCountry",
configWidget->getConfigToken(AssumaConfigWidget::Country) );
// qDebug() << "AssumaMainWindow::writeSettings() -> saved country is :"
<< configWidget->getConfigToken(AssumaConfigWidget::Country) ;
settings.setValue("configActivatedAddonList",
configWidget->getConfigToken(AssumaConfigWidget::ActivatedAddonList) );
settings.setValue("configCurrenciesList",
configWidget->getConfigToken(AssumaConfigWidget::CurrenciesList) );
settings.setValue("configCurrency",
configWidget->getConfigToken(AssumaConfigWidget::Currency) );

// Saving column status (showed or not)
settings.setValue("showFirstNameColumn",
actionShow_FirstName_column->isChecked() );
settings.setValue("showMaidenNameColumn",
actionShow_MaidenName_column->isChecked() );
settings.setValue("showLastNameColumn",
actionShow_LastName_column->isChecked() );
settings.setValue("showBirthDateColumn",
actionShow_BirthDate_column->isChecked() );
settings.setValue("showCityColumn", actionShow_City_column->isChecked()
);
settings.setValue("showPostalCodeColumn",
actionShow_PostalCode_column->isChecked() );
settings.setValue("showPhoneNumberColumn",
actionShow_PhoneNumber_column->isChecked() );
settings.setValue("showEmailColumn",
actionShow_Email_column->isChecked() );
settings.setValue("showActivityColumn",
actionShow_Activity_column->isChecked() );
settings.setValue("showLessonsNumberColumn",
actionShow_LessonsNumber_column->isChecked() );
settings.setValue("showLicenseLabelColumn",
actionShow_LicenseLabel_column->isChecked() );
settings.setValue("showDuesColumn", actionShow_Dues_column->isChecked()
);
settings.setValue("showDuesStatusColumn",
actionShow_DuesStatus_column->isChecked() );
settings.setValue("showSubscriptionDateColumn",
actionShow_SubscriptionDate_column->isChecked() );
settings.setValue("showMedicalCertificateStatusColumn",
actionShow_MedicalCertificateStatus_column->isChecked() );
settings.setValue("showLicenseNumberColumn",
actionShow_LicenseNumber_column->isChecked() );
settings.setValue("showCommentColumn",
actionShow_Comment_column->isChecked() );
settings.setValue("showPictureColumn",
actionShow_Picture_column->isChecked() );
}

void AssumaMainWindow::addAvatar( const QString& fileName){
QListWidgetItem *it = new QListWidgetItem(imagesListWidget);
it->setText( fileName );
it->setIcon( QPixmap(fileName) );
}

void AssumaMainWindow::on_treeWidget_itemChanged( QTreeWidgetItem * item, int
column ){
if(dontUpdateSubscribersList)
return;
QTreeWidgetItem *head = treeWidget->headerItem();
if( head->text(column) == tr("LastName") ){
if( item->text(elementColumn(tr("MaidenName"))).isEmpty() )
nameLabel->setText( item->text(column) + " " +
item->text(elementColumn(tr("FirstName"))) );
else
nameLabel->setText( item->text(column) + " " + "(" +
item->text(elementColumn(tr("MaidenName"))) + ")" + " " +
item->text(elementColumn(tr("FirstName"))) );
lastNameEdit->setText(item->text(column));
}
else if( head->text(column) == tr("FirstName") ){
if( item->text(elementColumn(tr("MaidenName"))).isEmpty() )
nameLabel->setText(
item->text(elementColumn(tr("LastName"))) + " " + item->text(column) );
else
nameLabel->setText(
item->text(elementColumn(tr("LastName"))) + " " + "(" +
item->text(elementColumn(tr("MaidenName"))) + ")" + " " + item->text(column) );
firstNameEdit->setText(item->text(column));
}
else if( head->text(column) == tr("MaidenName") ){
nameLabel->setText( item->text(elementColumn(tr("LastName"))) +
" " + "(" + item->text(column) + ")" + " " +
item->text(elementColumn(tr("FirstName"))) );
maidenNameEdit->setText(item->text(column));
}
else if( head->text(column) == tr("BirthDate") ){
birthDateEdit->setDate( QDate::fromString( item->text(
elementColumn( tr("BirthDate") ) ) , birthDateEdit->displayFormat() ) );
}
else if( head->text(column) == tr("Address") ){
addressEdit->setText( item->text( elementColumn( tr("Address")
) ) );
}
else if( head->text(column) == tr("City") ){
// int city_idx = cityEdit->findText ( item->text( elementColumn(
tr("City") ) ), Qt::MatchFixedString );
cityEdit->setText( item->text( elementColumn( tr("City") )
).toUpper() );
// qDebug() << "AssumaMainWindow-> cityEdit index found: " <<
city_idx;
// if( city_idx == -1 ){
//! \warning this code adds each letter typed in the
editor in the list of cities.
// qDebug() << "AssumaMainWindow-> inserting new city in
cityEdit : " << item->text( elementColumn( tr("City") ));
// cityEdit->insertItem(0,item->text( elementColumn(
tr("City") )));
// cityEdit->setCurrentIndex(0);
// }
// else
// cityEdit->setCurrentIndex(city_idx);
}
else if( head->text(column) == tr("PostalCode") ){
postalCodeEdit->setText( item->text( elementColumn(
tr("PostalCode") ) ).toUpper() );
// int pc_idx = postalCodeEdit->findText ( item->text(
elementColumn( tr("PostalCode") ) ), Qt::MatchFixedString );
// if( pc_idx == -1 ){
// postalCodeEdit->insertItem(0,item->text(
elementColumn( tr("PostalCode") )));
// postalCodeEdit->setCurrentIndex(0);
// }
// else
// postalCodeEdit->setCurrentIndex(pc_idx);
}
else if( head->text(column) == tr("Email") ){
emailEdit->setText( item->text( elementColumn( tr("Email") ) )
);
}
else if( head->text(column) == tr("PhoneNumber") ){
phoneNumberEdit->setText( item->text( elementColumn(
tr("PhoneNumber") ) ) );
}
else if( head->text(column) == tr("Activity") ){
int activity_index = activityComboBox->findText( item->text(
elementColumn( tr("Activity") ) ), Qt::MatchFixedString );
if( activity_index > -1 ){
activityComboBox->setCurrentIndex(activity_index);
treeWidgetDelegate->setCurrentActivity(item->text(
elementColumn( tr("Activity") ) ));
}
}
else if( head->text(column) == tr("LessonsNumber") ){
lessonsNumberEdit->setValue( item->text( elementColumn(
tr("LessonsNumber") ) ).toInt() );
lessonsNumberEdit->setMaximum(
configWidget->getMaxCoursesPerWeek( activityComboBox->currentText() ) );
}
else if( head->text(column) == tr("LicenseLabel") ){
// qDebug() << "AssumaMainWindow::on_treeWidget_itemChanged ->
item content changed at column" << column << "name:" << head->text(column);
int ll_idx = licenseLabelComboBox->findText ( item->text(
elementColumn( tr("LicenseLabel") ) ), Qt::MatchFixedString );
if( ll_idx == -1 ){
licenseLabelComboBox->setCurrentIndex(0);
item->setText( column,
licenseLabelComboBox->currentText() );
}
else
licenseLabelComboBox->setCurrentIndex(ll_idx);
}
else if( head->text(column) == tr("Dues") ){
duesEdit->setValue( calculateDue(item) );
}
else if( head->text(column) == tr("DuesStatus") ){
int ds_index = duesStatusEdit->findText( item->text(
elementColumn( tr("DuesStatus") ) ), Qt::MatchFixedString );
if( ds_index > -1 && ds_index != duesStatusEdit->currentIndex()
)
duesStatusEdit->setCurrentIndex(ds_index);
}
else if( head->text(column) == tr("SubscriptionDate") ){
subscriptionDateEdit->setDate( QDate::fromString( item->text(
elementColumn( tr("SubscriptionDate") ) ) ,
subscriptionDateEdit->displayFormat() ) );
}
else if( head->text(column) == tr("MedicalCertificateStatus") ){
int mcs_index = medicalStatuEdit->findText( item->text(
elementColumn( tr("MedicalCertificateStatus") ) ), Qt::MatchFixedString );
if( mcs_index > -1 && mcs_index !=
medicalStatuEdit->currentIndex() )
medicalStatuEdit->setCurrentIndex(mcs_index);
}
else if( head->text(column) == tr("LicenseNumber") ){
licenseNumberEdit->setText( item->text( elementColumn(
tr("LicenseNumber") ) ) );
}
else if( head->text(column) == tr("Comment") ){
commentEdit->setText( item->text( elementColumn( tr("Comment")
) ) );
}
setItemTooltip(item);
// setWindowTitle( QString("Association Subscribers Manager -
[%1][*]").arg(currentDatabase) );
// treeWidget->setWindowModified(true);
setWindowModified(true);
}

void AssumaMainWindow::setItemTooltip(QTreeWidgetItem *item){
QString toolTip;
QString picture = item->text( elementColumn(tr("Picture")) );
if( !picture.startsWith(":/") && !QFile::exists(picture) )
picture = ":/images/images/user_default.png";
toolTip.append("<div align=\"center\"><img src=\"" + picture + "\"
height=\"128\" width=\"128\" /></div><b>" + item->text(
elementColumn(tr("LastName")) ) + " ");
if( ! item->text( elementColumn(tr("MaidenName")) ).isEmpty() )
toolTip.append( "(" + item->text(
elementColumn(tr("MaidenName")) ) + ") " );
toolTip.append( item->text( elementColumn(tr("FirstName")) ) + "</b>" );

if( ! item->text( elementColumn(tr("BirthDate")) ).isEmpty() ){
QDate bday = QDate::fromString( item->text(
elementColumn(tr("BirthDate")) ) , "dd/MM/yyyy" );
QDate today = QDate::currentDate();
QDate age = today.addYears( - bday.year() );
age = age.addMonths( - bday.month() );
age = age.addDays( - bday.day() );
toolTip.append( "<br>" + QString::number(age.year()) + " " +
tr("years old") );
}

if( item->text( elementColumn(tr("DuesStatus")) ) == tr("Not ok") )
toolTip.append( "<table><tr><td valign=\"middle\"><img
src=\":/images/images/messagebox_warning.png\"/></td><td valign=\"middle\">" +
tr("<b>Dues to be paid</b>") + "</td></tr></table>" ) ;
if( item->text( elementColumn(tr("MedicalCertificateStatus")) ) ==
tr("Not ok") )
toolTip.append( "<table><tr><td valign=\"middle\"><img
src=\":/images/images/messagebox_warning.png\"/></td><td valign=\"middle\">" +
tr("<b>Medical certificate to provide</b>") + "</td></tr></table>" ) ;

toolTip.append( "<br>" + item->text( elementColumn(tr("Comment")) ) );

// Now set the tooltip for all column
for (int i = 0; i < treeWidget->columnCount(); i++ )
item->setToolTip( i, toolTip );
}

void AssumaMainWindow::on_treeWidget_currentItemChanged ( QTreeWidgetItem *
current, QTreeWidgetItem * previous ){
if(dontUpdateSubscribersList)
return;
// qDebug() << "AssumaMainWindow-> entering in
on_treeWidget_currentItemChanged ( QTreeWidgetItem * current, QTreeWidgetItem *
previous )";
if(previous && current && current != previous ){
if( !pc_map.contains( previous->text( elementColumn( tr("City")
) ) ) && pc_map.contains( previous->text( elementColumn( tr("City") )
).toUpper() ) )
previous->setText( elementColumn( tr("City") ),
previous->text( elementColumn( tr("City") ) ).toUpper() );
if( !pc_map.contains( previous->text( elementColumn( tr("City")
) ) ) ){
int r = QMessageBox::question ( treeWidget, tr("Add
postal code ?"),
tr("The city and postal code you entered (%1 -
%2) are not in the current list,\nDo you want to add it ?").arg(previous->text(
elementColumn( tr("City") ) )).arg(previous->text( elementColumn(
tr("PostalCode") ) )),
QMessageBox::Yes,
QMessageBox::No
);
if( r == QMessageBox::Yes ){
pc_map.insert( previous->text( elementColumn(
tr("City") ) ) , previous->text( elementColumn( tr("PostalCode") ) ) );
shouldSavePostalCodes=true;
if( treeWidgetDelegate )
treeWidgetDelegate->setPostCodesMap(
pc_map );
QCompleter *completer = new
QCompleter(pc_map.keys(), this);

completer->setCaseSensitivity(Qt::CaseInsensitive);
cityEdit->setCompleter(completer);
QCompleter *completer_pc = new
QCompleter(pc_map.values(), this);

completer_pc->setCaseSensitivity(Qt::CaseInsensitive);
postalCodeEdit->setCompleter(completer_pc);
}
}
else if( pc_map.contains( previous->text( elementColumn(
tr("City") ) ) ) && pc_map.value( previous->text( elementColumn( tr("City") ) )
) != previous->text( elementColumn( tr("PostalCode") ) ) ){
int r = QMessageBox::question ( treeWidget, tr("Modify
postal code ?"),
tr("The postal code you entered (%2) for
<b>%1</b> is not the one stored in our list,\nDo you want to replace <b>%3</b>
by <b>%2</b> in the list ?").arg(previous->text( elementColumn( tr("City") )
)).arg(previous->text( elementColumn( tr("PostalCode") ) )).arg( pc_map.value(
previous->text( elementColumn( tr("City") ) ) ) ),
QMessageBox::Yes,
QMessageBox::No
);
if( r == QMessageBox::Yes ){
pc_map.insert(previous->text( elementColumn(
tr("City") ) ) , previous->text( elementColumn( tr("PostalCode") ) ) );
shouldSavePostalCodes=true;
if( treeWidgetDelegate )
treeWidgetDelegate->setPostCodesMap(
pc_map );
QCompleter *completer = new
QCompleter(pc_map.keys(), this);

completer->setCaseSensitivity(Qt::CaseInsensitive);
cityEdit->setCompleter(completer);
QCompleter *completer_pc = new
QCompleter(pc_map.values(), this);

completer_pc->setCaseSensitivity(Qt::CaseInsensitive);
postalCodeEdit->setCompleter(completer_pc);
}
}
}
if( current && current != previous ){
QTreeWidgetItem *head = treeWidget->headerItem();
QString name = current->text( elementColumn(tr("FirstName")) );
name.append(" ");
if( ! current->text(elementColumn(tr("MaidenName"))).isEmpty() )
name.append( "(" +
current->text(elementColumn(tr("MaidenName"))) + ") " );
name.append( current->text( elementColumn(tr("LastName")) ) );
nameLabel->setText(name);
// Set picture viewer and editor
QPixmap pix;
if( current->text( elementColumn(tr("Picture"))
).startsWith("embedImage:") ){
QString img_str = current->text(
elementColumn(tr("Picture")) );
img_str.remove("embedImage:");
QByteArray bytes = QByteArray::fromBase64(
img_str.toAscii() );
pix.loadFromData( bytes );
}
else{
pix = QPixmap(
current->text(elementColumn(tr("Picture"))) ).scaled(QSize(128,128),
Qt::KeepAspectRatio);
}
if(!pix)
pix = QPixmap(":/images/images/user_default.png");
pictureEdit->setIcon( QIcon(pix) );
pictureEdit->setIconSize( pix.size() );
pictureLabel->setPixmap( pix );
// Build HTML for the text browser
//! \todo We should support themable html for the display of a
subscriber and produce this ugly html only as a default value
QString html;
for( int i=0; i < head->columnCount(); i++ ){
if( ! treeWidget->isColumnHidden(i) ){
html.append("<strong>");
html.append(head->text(i)); html.append(":</strong> ");
html.append(current->text(i));
if(head->text(i) == tr("Dues"))
html.append("
"+configWidget->getConfigToken(AssumaConfigWidget::Currency) );
html.append("<br/>");
}
}
textBrowser->setHtml(html);
// Set editors' values
firstNameEdit->setText( current->text( elementColumn(
tr("FirstName") ) ) );
maidenNameEdit->setText( current->text( elementColumn(
tr("MaidenName") ) ) );
lastNameEdit->setText( current->text( elementColumn(
tr("LastName") ) ) );
birthDateEdit->setDate( QDate::fromString( current->text(
elementColumn( tr("BirthDate") ) ) , birthDateEdit->displayFormat() ) );
subscriptionDateEdit->setDate( QDate::fromString(
current->text( elementColumn( tr("SubscriptionDate") ) ) ,
subscriptionDateEdit->displayFormat() ) );

int activity_index = activityComboBox->findText( current->text(
elementColumn( tr("Activity") ) ), Qt::MatchFixedString );
activityComboBox->setCurrentIndex(activity_index);
treeWidgetDelegate->setCurrentActivity(current->text(
elementColumn( tr("Activity") ) ));

lessonsNumberEdit->setValue( current->text( elementColumn(
tr("LessonsNumber") ) ).toInt() );
lessonsNumberEdit->setMaximum(
configWidget->getMaxCoursesPerWeek( activityComboBox->currentText() ) );

double due = calculateDue(current);
// qDebug() << "AssumaMainWindow::on_treeWidget_currentItemChanged
-> due =" << due;
duesEdit->setValue( due );

int ds_index = duesStatusEdit->findText( current->text(
elementColumn( tr("DuesStatus") ) ), Qt::MatchFixedString );
duesStatusEdit->setCurrentIndex(ds_index);

int mcs_index = medicalStatuEdit->findText( current->text(
elementColumn( tr("MedicalCertificateStatus") ) ), Qt::MatchFixedString );
medicalStatuEdit->setCurrentIndex(mcs_index);

// int city_idx = cityEdit->findText ( current->text(
elementColumn( tr("City") ) ), Qt::MatchFixedString );
// // qDebug() << "AssumaMainWindow-> cityEdit index found: " <<
city_idx;
// if( city_idx == -1 ){
// qDebug() << "AssumaMainWindow -> inserting into
cityEdit city name : " << current->text( elementColumn( tr("City") ));
// cityEdit->insertItem(0,current->text( elementColumn(
tr("City") )));
// cityEdit->setCurrentIndex(0);
// }
// else
// cityEdit->setCurrentIndex(city_idx);

QString postal_code = pc_map.value( current->text(
elementColumn( tr("City") ) ).toUpper() );
cityEdit->setText( current->text( elementColumn( tr("City") )
).toUpper() );
// Set the completer updated with the freshly added new city.
(hum... no : this is the role of the change detection code)
if( ! postal_code.isEmpty() ){
postalCodeEdit->setText( postal_code );
}
int ll_idx = licenseLabelComboBox->findText ( current->text(
elementColumn( tr("LicenseLabel") ) ), Qt::MatchFixedString );
// qDebug() << "AssumaMainWindow-> licenseLabelComboBox index
found: " << ll_idx;
if( ll_idx == -1 ){
//
licenseLabelComboBox->insertItem(0,current->text( elementColumn(
tr("LicenseLabel") )));
licenseLabelComboBox->setCurrentIndex(0);
}
else
licenseLabelComboBox->setCurrentIndex(ll_idx);

// int pc_idx = postalCodeEdit->findText ( current->text(
elementColumn( tr("PostalCode") ) ), Qt::MatchFixedString );
// // qDebug() << "AssumaMainWindow-> postalCodeEdit index found: "
<< pc_idx;
// if( pc_idx == -1 ){
// postalCodeEdit->insertItem(0,current->text(
elementColumn( tr("PostalCode") )));
// postalCodeEdit->setCurrentIndex(0);
// }
// else
// postalCodeEdit->setCurrentIndex(pc_idx);

addressEdit->setText( current->text( elementColumn(
tr("Address") ) ) );
phoneNumberEdit->setText( current->text( elementColumn(
tr("PhoneNumber") ) ) );
emailEdit->setText( current->text( elementColumn( tr("Email") )
) );
licenseNumberEdit->setText( current->text( elementColumn(
tr("LicenseNumber") ) ) );
commentEdit->setText( current->text( elementColumn(
tr("Comment") ) ) );
}
// qDebug() << "AssumaMainWindow->on_treeWidget_currentItemChanged (
QTreeWidgetItem * current, QTreeWidgetItem * previous ) : work done !";
}

// Editors modification slots

void AssumaMainWindow::on_firstNameEdit_textChanged( const QString & text){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("FirstName") ), text );
}
}

void AssumaMainWindow::on_maidenNameEdit_textChanged( const QString & text){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("MaidenName") ), text );
}
}

void AssumaMainWindow::on_lastNameEdit_textChanged( const QString & text){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("LastName") ), text );
}
}

void AssumaMainWindow::on_emailEdit_textChanged( const QString & text){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("Email") ), text );
}
}

void AssumaMainWindow::on_phoneNumberEdit_textChanged( const QString & text){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("PhoneNumber") ), text );
}
}

void AssumaMainWindow::on_licenseNumberEdit_textChanged( const QString & text){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("LicenseNumber") ), text );
}
}


void AssumaMainWindow::on_commentEdit_textChanged( const QString & text){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("Comment") ), text );
}
}

void AssumaMainWindow::on_subscriptionDateEdit_dateChanged ( const QDate & date
){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("SubscriptionDate") ),
date.toString( subscriptionDateEdit->displayFormat() ) );
}
}

void AssumaMainWindow::on_birthDateEdit_dateChanged ( const QDate & date ){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("BirthDate") ), date.toString(
birthDateEdit->displayFormat() ) );
}
}

void AssumaMainWindow::on_lessonsNumberEdit_valueChanged(const QString & text){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("LessonsNumber") ), text );
double debug_tmp = calculateDue(item);
// qDebug() <<
"AssumaMainWindow::on_lessonsNumberEdit_valueChanged -> debug_tmp from
calculateDue() =" << debug_tmp;
duesEdit->setValue( debug_tmp );
}
}

void AssumaMainWindow::on_duesEdit_valueChanged(double i){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
// qDebug() << "AssumaMainWindow-> on_duesEdit_valueChanged(const
QString & text): text=" << i;
item->setText( elementColumn( tr("Dues") ), QString::number(i)
);
}
}

void AssumaMainWindow::on_addressEdit_textChanged ( const QString & text ){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("Address") ), text );
}
}

void AssumaMainWindow::on_licenseLabelComboBox_currentIndexChanged ( int index
) {
// qDebug() << "AssumaMainWindow ->
on_licenseLabelComboBox_currentIndexChanged(int): index changed !";
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
// qDebug() << "AssumaMainWindow ->
on_licenseLabelComboBox_currentIndexChanged(int): changing main view
LicenseLabel text and recalculating dues.";
item->setText( elementColumn( tr("LicenseLabel") ),
licenseLabelComboBox->itemText(index) );
item->setData(elementColumn( tr("LicenseLabel") ),
AssumaMainWindow::IdRole, licenseLabelComboBox->itemData(
index,AssumaMainWindow::IdRole ) );
item->setData(elementColumn( tr("LicenseLabel") ),
AssumaMainWindow::FeeRole, licenseLabelComboBox->itemData(
index,AssumaMainWindow::FeeRole ) );
double due = calculateDue(item);
duesEdit->setValue(due);
}
}

void AssumaMainWindow::on_cityEdit_textChanged ( const QString & text ) {
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("City") ), text );
}
if( pc_map.value( cityEdit->text() ) != "" ){
QString postal_code = pc_map.value( cityEdit->text() ) ;
if( ! postal_code.isEmpty() )
postalCodeEdit->setText(postal_code);
}
}

void AssumaMainWindow::on_postalCodeEdit_textChanged ( const QString & text ){
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("PostalCode") ), text );
}
}

void AssumaMainWindow::on_duesStatusEdit_currentIndexChanged ( int index ) {
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
if( duesStatusEdit->itemText(index) == tr("Ok") )
item->setText( elementColumn( tr("DuesStatus") ), "1" );
else
item->setText( elementColumn( tr("DuesStatus") ), "0" );
exploitItemData(item);
}
}

void AssumaMainWindow::on_medicalStatuEdit_currentIndexChanged ( int index ) {
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
if( medicalStatuEdit->itemText(index) == tr("Ok") )
item->setText( elementColumn(
tr("MedicalCertificateStatus") ), "1" );
else
item->setText( elementColumn(
tr("MedicalCertificateStatus") ), "0" );
exploitItemData(item);
}
}

void AssumaMainWindow::on_activityComboBox_currentIndexChanged( int index ){
// qDebug() << "AssumaMainWindow -> Entering
on_activityComboBox_currenIndexChanged(" << index << ")";
// qDebug() << "AssumaMainWindow -> Activity column is number : " <<
elementColumn( tr("Activity") );
QTreeWidgetItem *item = treeWidget->currentItem() ;
if(item){
item->setText( elementColumn( tr("Activity") ),
activityComboBox->itemText(index) );
duesEdit->setValue( calculateDue(item) );
lessonsNumberEdit->setMaximum(
configWidget->getMaxCoursesPerWeek( activityComboBox->currentText() ) );
}
}

void AssumaMainWindow::on_pictureEdit_toggled(bool isChecked){
if(isChecked){
imagesListWidget->show();
addImagesButton->show();
}
else{
imagesListWidget->hide();
addImagesButton->hide();
}
}

void AssumaMainWindow::on_imagesListWidget_itemDoubleClicked ( QListWidgetItem
* item ){
QPixmap pix;
QTreeWidgetItem *current = treeWidget->currentItem() ;
if( QFile::exists( item->text() ) ){
current->setText(elementColumn(tr("Picture")), item->text() );
current->setIcon( 0, QIcon( item->text() ) );
}
else{
current->setText(elementColumn(tr("Picture")),
QString(":/images/images/%1").arg(item->text()) );
current->setIcon( 0, QIcon(
QString(":/images/images/%1").arg(item->text()) ) );
}
pix = QPixmap( current->text( elementColumn(tr("Picture")) )
).scaled(QSize(128,128), Qt::KeepAspectRatio);
pictureEdit->setIcon( QIcon( pix ) );
pictureEdit->setIconSize( pix.size() );
}

void AssumaMainWindow::on_deleteSubscriberButton_clicked() {
// qDebug() << "AssumaMainWindow-> deleteSubscriberButton clicked" ;
QList<QTreeWidgetItem *> item_list = treeWidget->selectedItems();
if( item_list.size() > 0 ){
int r = QMessageBox::question ( treeWidget, tr("Delete
subscribers ?"),
tr("You are about to delete %1
subscriber(s),\nDo you want to continue ?").arg(item_list.size()),
QMessageBox::Yes,
QMessageBox::No
);
if(r == QMessageBox::Yes){
foreach( QTreeWidgetItem *it, item_list ){
int index = treeWidget->indexOfTopLevelItem(it);
// qDebug() << "Index of element " << it->text(
elementColumn( tr("FirstName") ) ) << " " << it->text( elementColumn(
tr("LastName") ) ) << " is : " << index;
treeWidget->takeTopLevelItem(index);
}
showPassiveMessage( tr("%1 subscriber(s) have been
deleted from this database.<br>To commit this deletion(s) you have to save your
database.").arg(item_list.size() ) );
// treeWidget->setWindowModified(true);
setWindowModified(true);
on_treeWidget_itemSelectionChanged();
}
}
}

void AssumaMainWindow::addSubscriber( QTreeWidgetItem *item ){
// qDebug() << "AssumaMainWindow->addSubscriber() adding new item : " <<
item ;
treeWidget->addTopLevelItem(item);
// treeWidget->setWindowModified(true);
setWindowModified(true);
}

void AssumaMainWindow::subscribersImported(QList<QTreeWidgetItem*>*
imported_list){
// qDebug() << "AssumaMainWindow->subscribersImported(): got a " <<
imported_list->size() << " long list.";
int firstNameColumn = elementColumn(tr("FirstName")) ;
int lastNameColumn = elementColumn(tr("LastName")) ;
if( imported_list->isEmpty() )
return;
QTreeWidgetItem *importedHead = imported_list->takeFirst();
for (int i = 0; i < imported_list->size(); ++i){
QTreeWidgetItem *tmp_item = imported_list->at(i) ;
// qDebug() << "AssumaMainWindow->subscribersImported(): got " <<
tmp_item->text(0) << " " << tmp_item->text(2);
QList<QTreeWidgetItem *> tmp_list = treeWidget->findItems(
tmp_item->text( elementColumn(importedHead, tr("FirstName") ) ) ,
Qt::MatchFixedString , firstNameColumn );
if( tmp_list.size() > 0 ){
bool shouldImport = true;
for( int k = 0; k < tmp_list.size(); ++k ){
QTreeWidgetItem *it = tmp_list.at(k) ;
if( it->text( lastNameColumn ) ==
tmp_item->text( elementColumn(importedHead, tr("LastName") ) ) ) {
int r = QMessageBox::question ( this,
tr("Subscriber already
exists"),
tr("The subscriber you try to
import (<b>%1 %2 born %3</b>)<br>is already in the database as:<br><b>%4 %5
born %6</b>.<br><br>Do you want to import it anyway ?<br><br><i>(Yes will
import the new subscriber without removing the one already present, No will
discard importation)</i>.").arg(tmp_item->text( elementColumn(importedHead,
tr("FirstName") ) ))
.arg(tmp_item->text(
elementColumn(importedHead, tr("LastName") ) ))
.arg(tmp_item->text(
elementColumn(importedHead, tr("BirthDate") ) ))
.arg(it->text(
firstNameColumn ))
.arg(it->text(
lastNameColumn ))
.arg(it->text(
elementColumn(tr("BirthDate")) ))

,QMessageBox::Yes|QMessageBox::No, QMessageBox::Yes
);
if( r == QMessageBox::No)
shouldImport=false;
}
}
if( shouldImport ){
QTreeWidgetItem *newItem = new QTreeWidgetItem ;
QTreeWidgetItem *treeHead =
treeWidget->headerItem();
for (int f = 0 ; f <= treeHead->columnCount() ;
f++ ){
newItem->setText( f, tmp_item->text(
elementColumn( importedHead, treeHead->text(f) ) ) );
}
newItem->setIcon(0, QIcon( newItem->text(
elementColumn(tr("Picture") ) ) ) );
exploitItemData(newItem);
setItemTooltip(newItem);
addSubscriber(newItem);
}
}
else{
QTreeWidgetItem *newItem = new QTreeWidgetItem ;
QTreeWidgetItem *treeHead = treeWidget->headerItem();
for (int f = 0 ; f <= treeHead->columnCount() ; f++ ){
newItem->setText( f, tmp_item->text(
elementColumn( importedHead, treeHead->text(f) ) ) );
}
newItem->setIcon(0, QIcon( newItem->text(
elementColumn(tr("Picture") ) ) ) );
exploitItemData(newItem);
setItemTooltip(newItem);
addSubscriber(newItem);
}
}
}

QString AssumaMainWindow::subscribersListToString(const QString& separator,
bool addHeaders){
QString text;
QTreeWidgetItem *rootitem = treeWidget->invisibleRootItem();
if( addHeaders ){
QTreeWidgetItem *header = treeWidget->headerItem();
QStringList clipline;
for ( int j=0 ; j < header->columnCount() ; ++j ){
clipline << header->text(j);
}
text.append( clipline.join(separator) );
text.append("\n");
}
for(int k=0;k<rootitem->childCount(); k++)
{
QTreeWidgetItem *it = rootitem->child(k);
QStringList clipline;
for ( int j=0 ; j < it->columnCount() ; ++j ){
clipline << it->text(j);
}
text.append( clipline.join(separator) );
text.append("\n");
}
return text;
}

// Action toggle slots

void AssumaMainWindow::on_addImagesButton_clicked(){
QString fileName = QFileDialog::getOpenFileName(this, tr("Open
image..."),currentDatabase,tr("Images files (*.png *.jpg *.jpeg *.bmp *.svg
*.gif)"));
if( ! fileName.isEmpty() ){
addAvatar(fileName);
}
}

void AssumaMainWindow::on_actionExport_to_Excel_activated(){
QString file_name = currentDatabase ;
file_name.replace(".adb",".xls");
// qDebug() << "AssumaMainWindow->on_actionExport_to_Excel_activated() XLS
data should be exported to : " << file_name ;
file_name = QFileDialog::getSaveFileName(this, tr("Save
File"),file_name,tr("Microsoft Excel files (*.xls)"));
if( !file_name.isEmpty() ){
// qDebug() <<
"AssumaMainWindow->on_actionExport_to_Excel_activated() XLS data will be
exported to : " << file_name ;
QFile file(file_name);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
QMessageBox::critical(this,tr("Write error"),
tr("We are unable to write the XLS file.\nWe cannot open %1 for
writting.").arg(file_name) );
return;
}
QTextStream out(&file);
//out.setCodec("UTF-8");
// TODO: we have to set here the codec depending on the
configured one.
out.setCodec("ISO-8859-1");
out << subscribersListToString("\t",true).toLatin1() << "\n";
showPassiveMessage( tr("database: <strong>%1</strong><br>was
exported to <br>Excel file:
<strong>%2</strong>").arg(currentDatabase).arg(file_name) );
}
// else
// qDebug() <<
"AssumaMainWindow->on_actionExport_to_Excel_activated() XLS exportation aborded
!!" ;
}

void AssumaMainWindow::on_actionExport_to_CSV_activated() {
QString file_name = currentDatabase ;
file_name.replace(".adb",".csv");
// qDebug() << "AssumaMainWindow->on_actionExport_to_CSV_activated() CSV
data should be exported to : " << file_name ;
file_name = QFileDialog::getSaveFileName(this, tr("Save
File"),file_name,tr("Comma Separated files (*.csv)"));
if( !file_name.isEmpty() ){
// qDebug() <<
"AssumaMainWindow->on_actionExport_to_CSV_activated() CSV data will be exported
to : " << file_name ;
QFile file(file_name);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
QMessageBox::critical(this,tr("Write error"),
tr("We are unable to write the CSV file.\nWe cannot open %1 for
writting.").arg(file_name) );
return;
}
QTextStream out(&file);
out.setCodec("UTF-8");
out << subscribersListToString(" ; ",true) << "\n";
showPassiveMessage( tr("database: <strong>%1</strong><br>was
exported to <br>CSV file:
<strong>%2</strong>").arg(currentDatabase).arg(file_name) );
}
// else
// qDebug() <<
"AssumaMainWindow->on_actionExport_to_CSV_activated() CSV exportation aborded
!!" ;
}

void AssumaMainWindow::on_actionExport_to_HTML_activated() {
QString file_name = currentDatabase ;
file_name.replace(".adb",".html");
// qDebug() << "AssumaMainWindow->on_actionExport_to_HTML_activated() HTML
data should be exported to : " << file_name ;
file_name = QFileDialog::getSaveFileName(this, tr("Save
File"),file_name,tr("HTML files (*.htm *.html)"));
if( !file_name.isEmpty() ){
// qDebug() <<
"AssumaMainWindow->on_actionExport_to_HTML_activated() HTML data will be
exported to : " << file_name ;
QFile file(file_name);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)){
QMessageBox::critical(this,tr("Write error"),
tr("We are unable to write the HTML file.\nWe cannot open %1 for
writting.").arg(file_name) );
return;
}
QTreeWidgetItem *rootitem = treeWidget->invisibleRootItem();
QTextStream out(&file);
out.setCodec("UTF-8");
out << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0
Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\";>\n";
out << "<html xmlns=\"http://www.w3.org/1999/xhtml\";
xml:lang=\"en\" lang=\"en\">\n";
out << "<head>\n" ;
out << "<title>" <<
configWidget->getConfigToken(AssumaConfigWidget::AssociationName) << ": " <<
tr("Subscribers list") << "</title>\n";
out << "<meta http-equiv=\"Content-type\" content=\"text/html;
charset=utf-8\" />";
out << "<style type=\"text/css\"><!--\n";
out << "table.table { border-top: 1px solid black;
border-bottom: 1px solid black; border-left: 1px solid black;}\n";
out << ".table_cell { border-top: 1px solid black;
border-right: 1px solid black; text-align : center; } \n";
out << "th { border-right: 1px solid black;}\n";
out << ".table_row_header { background: #80acff;}\n";
out << ".table_row_odd { background: #a2d7ff;}\n";
out << ".table_row:hover, .table_row_odd:hover { background:
#a7bfd2;}\n";
out << "#info_box { border: 1px solid black;}\n";
out << ".box_title { position: relative; width: 100%;
background: #80acff; }\n";
out << " --></style>";
out << "</head>\n<body>\n";
out << "<div id=\"info_box\">\n";
out << "<div class=\"box_title\"><strong>" << tr("Association:
") << "</strong>" <<
configWidget->getConfigToken(AssumaConfigWidget::AssociationName) << "</div>\n";
out << "<strong>" << tr("Number of subscribers") << ":
</strong>" << rootitem->childCount() << "<br/>\n";
out << "</div><br/>\n";
out << "<table class=\"table\" cellspacing=\"0\">\n";
QTreeWidgetItem *header = treeWidget->headerItem();
out << "<tr class=\"table_row_header\">\n";
for ( int j=0 ; j < header->columnCount() ; ++j ){
if(header->text(j) != tr("Picture"))
out << "<th>" << header->text(j) << "</th>";
}
out << "</th>\n";
bool isOdd = false;
for(int k=0;k<rootitem->childCount(); k++)
{
QTreeWidgetItem *it = rootitem->child(k);
if(isOdd){
out << "<tr class=\"table_row_odd\">" ;
isOdd = false;
}
else{
out << "<tr class=\"table_row\">" ;
isOdd = true;
}
for ( int j=0 ; j < it->columnCount() ; ++j ){
if(header->text(j) != tr("Picture"))
out << "<td class=\"table_cell\">" <<
it->text(j) << "</td>";
}
out << "</tr>\n";
}
out << "</table>\n</body>\n</html>\n";
showPassiveMessage( tr("database: <strong>%1</strong><br>was
exported to <br>HTML file:
<strong>%2</strong>").arg(currentDatabase).arg(file_name) );
}
// else
// qDebug() <<
"AssumaMainWindow->on_actionExport_to_HTML_activated() HTML exportation aborded
!!" ;
}

void AssumaMainWindow::on_actionAdd_a_subscriber_activated(){
QTreeWidgetItem *it = new QTreeWidgetItem(QStringList() << tr("New") <<
tr("") << tr("Subscriber"));
it->setText( elementColumn( tr("Picture") ),
":/images/images/user_default.png" );
it->setFlags(it->flags() | Qt::ItemIsEditable);
it->setIcon(0,QIcon(":/images/images/user_default.png") );
addSubscriber(it);
treeWidget->setCurrentItem(it,0,QItemSelectionModel::Select);
actionEdit_subscriber->setChecked(true);
}

void
AssumaMainWindow::on_actionAbout_Association_Subscribers_Manager_activated(){
QWidget * w = new QWidget(this);
w->resize(300,90);
QPalette palette;
QBrush brush(QColor(255, 255, 255, 255));
brush.setStyle(Qt::SolidPattern);
palette.setBrush(QPalette::Active, QPalette::Base, brush);
QBrush brush1(QColor(145, 233, 150, 220));
brush1.setStyle(Qt::SolidPattern);
palette.setBrush(QPalette::Active, QPalette::Window, brush1);
palette.setBrush(QPalette::Inactive, QPalette::Base, brush);
palette.setBrush(QPalette::Inactive, QPalette::Window, brush1);
palette.setBrush(QPalette::Disabled, QPalette::Base, brush1);
palette.setBrush(QPalette::Disabled, QPalette::Window, brush1);
w->setPalette(palette);
w->setAutoFillBackground(true);

QPushButton *pushButton = new QPushButton(w);
pushButton->setMaximumSize(QSize(17, 17));
QIcon icon;
icon.addPixmap(QPixmap(QString::fromUtf8(":/images/images/close.png")),
QIcon::Normal, QIcon::Off);
pushButton->setIcon(icon);
pushButton->setFlat(true);
QVBoxLayout *l = new QVBoxLayout ;
l->addWidget(pushButton);
l->addStretch();

w->setLayout( new QHBoxLayout );
QLabel *pix_label = new QLabel(w);
pix_label->setPixmap( QPixmap(":/images/images/as.png").scaled(80,80) );
pix_label->setMaximumWidth(90);
w->layout()->addWidget( pix_label );
QLabel *text_label = new QLabel(w);
text_label->setOpenExternalLinks(true);
text_label->setText( tr("<html><body><strong>Association Subscribers
Manager - v%1 - Arnaud Dupuis</strong><br>Brazilian Portuguese translation:
Diego Ferreira<br>Swedish translation: Daniel Persson<br>Romanian translation:
Lucian Lupescu<br>Documentation French translation: Fabrice Eyraud<br><a
href=\"https://sourceforge.net:443/tracker/?group_id=211536\";>Bug
report/feature request</a><br><a
href=\"http://www.associationsubscribersmanager.org\";>Official
website</a><br>&copy; 2006 - 2009 Infinity
Perl</body></html>").arg(ASSUMA_VERSION) );
w->layout()->addWidget( text_label );
((QBoxLayout *)w->layout())->addLayout( l );

if(text_label->sizeHint() != text_label->size()){
int delta_height = text_label->sizeHint().height() -
text_label->size().height();
int delta_width = text_label->sizeHint().width() -
text_label->size().width();
QSize s = w->size();
s.setHeight( s.height() + delta_height );
if( s.height() < 50 )
s.setHeight(50);
if( s.height() < (height() / 10) )
s.setHeight(height() / 10);
s.setWidth( s.width() + delta_width );
w->resize(s);
}

AssumaEffect *effect = new
AssumaEffect(0,w,AssumaEffect::SLIDE_FROM_BOTTOM);
effect->setTimeBeforeReversing(30000);
connect( pushButton, SIGNAL(clicked()), effect, SLOT( reverseEffect() )
);
effect->doEffect();

// showPassiveMessage(tr("<strong>Association Subscribers Manager -
v3.0rc1 - Arnaud Dupuis</strong><br>Brazilian Portuguese translation: Diego
Ferreira<br>Swedish translation: Daniel Persson<br>Romanian translation: Lucian
Lupescu<br>&copy; 2006 - 2009 Infinity Perl"),
QPixmap(":/images/images/as.png") );
}

void
AssumaMainWindow::on_actionAssociation_Subscribers_Manager_manual_activated(){
AssumaHelpBrowser *helpBrowser = new AssumaHelpBrowser(this);
if(
configWidget->getConfigToken(AssumaConfigWidget::Language).startsWith("Fra") )
helpBrowser->setUrl( QUrl(
QString(ASSUMA_DOCDIR).append("/user/assuma_subscribers_database_doc_fr.html")
) );
else
helpBrowser->setUrl( QUrl(
QString(ASSUMA_DOCDIR).append("/user/assuma_subscribers_database_doc.html") ) );
helpBrowser->show();
}

void AssumaMainWindow::on_action_Copy_activated(){
QList<QTreeWidgetItem *> item_list = treeWidget->selectedItems();
QClipboard *clipboard = QApplication::clipboard();
QStringList clip;
for (int i = 0; i < item_list.size(); ++i){
QTreeWidgetItem *it = item_list.at(i);
QStringList clipline;
for ( int j=0 ; j < it->columnCount() ; ++j ){
clipline << it->text(j);
}
clip << clipline.join("\t");
}
clipboard->setText( clip.join("\n") );
}

void AssumaMainWindow::on_actionPaste_activated(){
QClipboard *clipboard = QApplication::clipboard();
QString originalText = clipboard->text();
foreach (QString text, originalText.split("\n") ){
QStringList strlst = text.split( QRegExp("(\t|,|;)") );
QTreeWidgetItem *it = new QTreeWidgetItem(strlst);
addSubscriber(it);
treeWidget->setCurrentItem(it,0,QItemSelectionModel::Select);
actionEdit_subscriber->setChecked(true);
exploitItemData(it);
}
}

void AssumaMainWindow::on_actionShow_FirstName_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("FirstName")) );
else
treeWidget->hideColumn( elementColumn(tr("FirstName")) );
}

void AssumaMainWindow::on_actionShow_MaidenName_column_toggled (bool isChecked)
{
if(isChecked)
treeWidget->showColumn( elementColumn(tr("MaidenName")) );
else
treeWidget->hideColumn( elementColumn(tr("MaidenName")) );
}

void AssumaMainWindow::on_actionShow_LastName_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("LastName")) );
else
treeWidget->hideColumn( elementColumn(tr("LastName")) );
}

void AssumaMainWindow::on_actionShow_BirthDate_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("BirthDate")) );
else
treeWidget->hideColumn( elementColumn(tr("BirthDate")) );
}

void AssumaMainWindow::on_actionShow_Address_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("Address")) );
else
treeWidget->hideColumn( elementColumn(tr("Address")) );
}

void AssumaMainWindow::on_actionShow_City_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("City")) );
else
treeWidget->hideColumn( elementColumn(tr("City")) );
}

void AssumaMainWindow::on_actionShow_PostalCode_column_toggled (bool isChecked)
{
if(isChecked)
treeWidget->showColumn( elementColumn(tr("PostalCode")) );
else
treeWidget->hideColumn( elementColumn(tr("PostalCode")) );
}

void AssumaMainWindow::on_actionShow_PhoneNumber_column_toggled (bool
isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("PhoneNumber")) );
else
treeWidget->hideColumn( elementColumn(tr("PhoneNumber")) );
}

void AssumaMainWindow::on_actionShow_MobilePhone_column_toggled (bool
isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("MobilePhone")) );
else
treeWidget->hideColumn( elementColumn(tr("MobilePhone")) );
}

void AssumaMainWindow::on_actionShow_Email_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("Email")) );
else
treeWidget->hideColumn( elementColumn(tr("Email")) );
}

void AssumaMainWindow::on_actionShow_LessonsNumber_column_toggled (bool
isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("LessonsNumber")) );
else
treeWidget->hideColumn( elementColumn(tr("LessonsNumber")) );
}

void AssumaMainWindow::on_actionShow_LicenseLabel_column_toggled (bool
isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("LicenseLabel")) );
else
treeWidget->hideColumn( elementColumn(tr("LicenseLabel")) );
}

void AssumaMainWindow::on_actionShow_Activity_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("Activity")) );
else
treeWidget->hideColumn( elementColumn(tr("Activity")) );
}

void AssumaMainWindow::on_actionShow_Dues_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("Dues")) );
else
treeWidget->hideColumn( elementColumn(tr("Dues")) );
}

void AssumaMainWindow::on_actionShow_DuesStatus_column_toggled (bool isChecked)
{
if(isChecked)
treeWidget->showColumn( elementColumn(tr("DuesStatus")) );
else
treeWidget->hideColumn( elementColumn(tr("DuesStatus")) );
}

void AssumaMainWindow::on_actionShow_SubscriptionDate_column_toggled (bool
isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("SubscriptionDate")) );
else
treeWidget->hideColumn( elementColumn(tr("SubscriptionDate")) );
}

void AssumaMainWindow::on_actionShow_MedicalCertificateStatus_column_toggled
(bool isChecked) {
if(isChecked)
treeWidget->showColumn(
elementColumn(tr("MedicalCertificateStatus")) );
else
treeWidget->hideColumn(
elementColumn(tr("MedicalCertificateStatus")) );
}

void AssumaMainWindow::on_actionShow_LicenseNumber_column_toggled (bool
isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("LicenseNumber")) );
else
treeWidget->hideColumn( elementColumn(tr("LicenseNumber")) );
}

void AssumaMainWindow::on_actionShow_Comment_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("Comment")) );
else
treeWidget->hideColumn( elementColumn(tr("Comment")) );
}

void AssumaMainWindow::on_actionShow_Picture_column_toggled (bool isChecked) {
if(isChecked)
treeWidget->showColumn( elementColumn(tr("Picture")) );
else
treeWidget->hideColumn( elementColumn(tr("Picture")) );
}

void AssumaMainWindow::on_actionEdit_subscriber_toggled(bool isChecked){
if( isChecked && configWidget->isVisible() ){
actionSettings->setChecked(false);
}
}

void AssumaMainWindow::on_actionSettings_toggled(bool isChecked){
if( isChecked ){
if( actionEdit_subscriber->isChecked() )
actionEdit_subscriber->setChecked(false);
splitter->hide();
configWidget->show();
}
else{
duesEdit->setSuffix( " "+configWidget->getConfigToken(
AssumaConfigWidget::Currency ) );
configWidget->hide();
splitter->show();
if( !action_Find->isChecked() )
searchWidget->hide();
treeWidget->setCurrentItem(0);
activityComboBox->clear();
activityComboBox->addItems( configWidget->getCoursesList() );
QString _pc_file =
configWidget->getConfigToken(AssumaConfigWidget::DataDir) + "/PostalCodes/" +
configWidget->getConfigToken(AssumaConfigWidget::Country) + ".cities.xml" ;
if( _pc_file != postal_codes_filename ){
postal_codes_filename = _pc_file;
loadPostalCodes( postal_codes_filename );
}

if(
configWidget->getConfigToken(AssumaConfigWidget::Federation) !=
currentFederation && treeWidget->topLevelItemCount() > 0 ){
loadFederation(
configWidget->getConfigToken(AssumaConfigWidget::Federation) );
int ret = QMessageBox::question(this,tr("Association
Subscribers Manager"),tr("The federation have changed, it is recommended to
reload the subscribers' database.\nDo you want to reload it now (the database
will be saved before reload) ?"),QMessageBox::Yes|QMessageBox::No);
if( ret == QMessageBox::Yes){
if( QFile::exists(currentDatabase) ){
on_action_Save_activated();
loadDatabase(currentDatabase);
}
else{
showPassiveMessage(tr("<html>Database
not reloaded.<br>File <strong>%1</strong> does not
exist.<html>").arg(currentDatabase));
}
}
}

// Test
// qDebug() << "TrimesterCount: " <<
configWidget->getConfigToken(AssumaConfigWidget::TrimesterCount);
// qDebug() << "UpdatesOnStart: " <<
configWidget->getConfigToken(AssumaConfigWidget::UpdatesOnStart);
// qDebug() << "ContactsList: " <<
configWidget->getConfigToken(AssumaConfigWidget::ContactsList);
// qDebug() << "CoursesList: " <<
configWidget->getConfigToken(AssumaConfigWidget::CoursesList);
// qDebug() << "All courses price for 1 course : " <<
configWidget->getCourseFee("All courses", 1);
}
}

void AssumaMainWindow::on_actionUpdate_activated(){
// qDebug() << "Trying to update !!";
AssumaUpdateDialog *dial = new AssumaUpdateDialog(this);
connect( dial, SIGNAL(updateFinished(bool)), this, SLOT(
finishUpdate(bool) ) );
this->setVisible(false);
dial->show();

}

void AssumaMainWindow::finishUpdate(bool haveBeenUpdated){
this->setVisible(true);
if(haveBeenUpdated)
showPassiveMessage( tr("Association Subscribers Manager have
been updated, you should restart it now.") );
}

void AssumaMainWindow::on_sendSummaryButton_clicked(){
AssumaMailDialog *dial = createMailDialog();
QTreeWidgetItem *item = treeWidget->currentItem();
if( item->text( elementColumn( tr("Email") ) ).size() > 5 )
dial->addEmail( item->text( elementColumn( tr("Email")
) ) );
QString body(tr("Hello %SUBSCRIBER_FIRSTNAME%,\n\nPlease find bellow
your dues details:\nActivity: %SUBSCRIBER_ACTIVITY%\nLessons' number:
%SUBSCRIBER_LESSONSNUMBER%\nDues: %SUBSCRIBER_DUES% %CURRENCY%\nDues status:
%SUBSCRIBER_DUESSTATUS%\nMedical certificate status:
%SUBSCRIBER_MEDICALCERTIFICATESTATUS%\n\nBest regards,\n%ASSO_NAME%"));
dial->setSubject( processTemplate( tr("[%ASSO_NAME%] Dues details") ) );
dial->setBody( processTemplate(body) );
dial->show();
}

// eof
< Previous Next >
Follow Ups