Logo Search packages:      
Sourcecode: ecawave version File versions  Download package

ecawave.cpp

// ------------------------------------------------------------------------
// ecawave.cpp: Ecawave initialization and startup routines.
// Copyright (C) 1999-2002 Kai Vehmanen (kai.vehmanen@wakkanet.fi)
//
// 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 2 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 <iostream>
#include <signal.h> /* sigaction() */

#include <qapplication.h>

#include <kvu_com_line.h>
#include <eca-error.h>
#include <eca-logger.h>
#include <eca-version.h>

#include "version.h"
#include "ecawave.h"
#include "qeinterface.h"
#include "qesession.h"

using namespace std;

static void ecawave_signal_handler(int signum);
static void ecawave_setup_signals(void);

int main(int argc, char **argv) {

  ecawave_setup_signals();

  ECA_LOGGER::instance().disable();
  // ECA_LOGGER::instance().set_log_level(ECA_LOGGER::errors, true);
  // ECA_LOGGER::instance().set_log_level(ECA_LOGGER::info, true);
  // ECA_LOGGER::instance().set_log_level(ECA_LOGGER::subsystems, true);

  try {
    COMMAND_LINE cline = COMMAND_LINE (argc, argv);
    parse_command_line(cline);

    QApplication qapp (argc, argv);
    string param;
    if (argc > 1) param = string(argv[1]);
    QEInterface ewinterface (param);
    qapp.setMainWidget(&ewinterface);
    ewinterface.show();
    
    QObject::connect( &qapp, SIGNAL( lastWindowClosed() ), &qapp, SLOT( quit() ) );
    return(qapp.exec());
  }
  catch(ECA_ERROR& e) { 
    std::cerr << "---\nlibecasound error while processing event: [" << e.error_section() << "] : \"" << e.error_message() << "\"\n\n";
  }
  catch(...) {
    std::cerr << "---\nCaught an unknown exception!\n";
  }
}

void ecawave_signal_handler(int signum) {
  std::cerr << "(ecawave) <-- Caught a signal... cleaning up." << std::endl << std::endl;
  exit(0);
}

void ecawave_setup_signals(void)
{
  struct sigaction es_handler;
  es_handler.sa_handler = ecawave_signal_handler;
  sigemptyset(&es_handler.sa_mask);
  es_handler.sa_flags = 0;

  struct sigaction ign_handler;
  ign_handler.sa_handler = SIG_IGN;
  sigemptyset(&ign_handler.sa_mask);
  ign_handler.sa_flags = 0;

  /* handle the follwing signals explicitly */
  sigaction(SIGTERM, &es_handler, 0);
  sigaction(SIGINT, &es_handler, 0);

  /* ignore the following signals */
  sigaction(SIGPIPE, &ign_handler, 0);
}

void parse_command_line(COMMAND_LINE& cline) {
  cline.begin();
  while(cline.end() == false) {
    if (cline.current() == "--version") {
      cout << "ecawave "
         << ecawave_version
         << " - [libecasound "
         << ecasound_library_version
         << "]" << endl;
      cout << "Copyright (C) 1999-2003 Kai Vehmanen" << endl;
      cout << "Ecawave comes with ABSOLUTELY NO WARRANTY." << endl;
      cout << "You may redistribute copies of ecawave under the terms of the GNU" << endl;
      cout << "General Public License. For more information about these matters, see" << endl; 
      cout << "the file named COPYING." << endl;
      exit(0);
    }
    else if (cline.current() == "--help") {
      cout << "USAGE: ecawave [options] filename\n" 
           << "    --version   print version info" << endl
           << "    --help      show this help" << endl << endl;
      cout << "For a more detailed documentation, see ecawave(1) man  page." << endl;
      cout << "Report bugs to <k@eca.cx>." << endl;
      exit(0);
      }
    cline.next();
  }
}

Generated by  Doxygen 1.6.0   Back to index