Exemplo n.º 1
0
config_gui_main::config_gui_main(app_config &context) :
    context(context),
    preset_it("Impulse Tracker"),
    preset_xm("FastTracker 2"),
    preset_mpt("Classic Modplug"),
    preset_buzz("Buzz")
{
    demo_dummy = std::unique_ptr<module_renderer>(new module_renderer());
    demo_dummy->ChangeModTypeTo(MOD_TYPE_IT);
    demo_dummy->m_nChannels = 3;
    demo_dummy->InitChannel(1);
    demo_dummy->InitChannel(2);
    demo_dummy->InitChannel(3);
    demo_dummy->Patterns.Insert(64);

    demo = new pattern_editor(
        *demo_dummy.get(),
        emptymap,
        emptymap,
        emptymap,
        context.colors()
    );
    demo->setMinimumHeight(100);
    demo->setMinimumWidth(100);

    auto box = new QComboBox;
    for_each(color_names, [&] (color_name_assoc_t color) {
        box->addItem(color.value, QVariant(color.key));
    });

    auto wire = [&] (QPushButton &b) { connect(
        &b, &QPushButton::clicked,
        this, &config_gui_main::preset_clicked
    ); };

    wire(preset_it);
    wire(preset_xm);
    wire(preset_mpt);
    wire(preset_buzz);

    auto layout = new QVBoxLayout(this);
    layout->addWidget(box);
    layout->addWidget(demo);
    layout->addWidget(&preset_it);
    layout->addWidget(&preset_xm);
    layout->addWidget(&preset_mpt);
    layout->addWidget(&preset_buzz);

    refresh();
};
Exemplo n.º 2
0
config_audioio_main::config_audioio_main(app_config &context) :
    context(context), _modified(false)
{
    auto layout = new QGridLayout(this);

    buflen.setSuffix(" samples");
    buflen.setMinimum(0);
    buflen.setMaximum(5678);
    buflen.setSingleStep(32);

    channels.setMinimum(0);

    int row = 0;
    auto add_widget = [&](char *name, QWidget &widget) {
        layout->addWidget(new QLabel(name), row, 0);
        layout->addWidget(&widget, row, 1);
        ++row;
    };

    add_widget("Output Device:", devices);
    add_widget("Sample Rate:", rates);
    add_widget("Buffer Length:", buflen);
    add_widget("Output Channels:", channels);
    add_widget("Output Latency:", latency);

    layout->addItem(
        new QSpacerItem(
            0, 0,
            QSizePolicy::MinimumExpanding,
            QSizePolicy::MinimumExpanding
        ),
        row, 1
    );

    for_each(supported_sample_rates, [&](sample_rate_assoc t) {
        rates.addItem(t.value, QVariant(t.key));
    });

    auto &pa_system = context.audio_handle();

    for (auto i = pa_system.devicesBegin(); i != pa_system.devicesEnd(); ++i) {
        if (i->maxOutputChannels() > 0) {
            devid_hostapi_pack pack;
            pack.devid = i->index();
            pack.hostapi = i->hostApi().typeId();
            devices.addItem(
                QString("%1: %2").arg(i->hostApi().name()).arg(i->name()),
                QVariant(pack.packed)
            );
        }
    }
    auto combo_changed = static_cast<void(QComboBox::*)(int)>(
        &QComboBox::currentIndexChanged
    );

    auto spin_changed = static_cast<void(QSpinBox::*)(int)>(
        &QSpinBox::valueChanged
    );

    auto connect_change_notifiers = [&] () {
        connect(
            &devices, combo_changed,
            this, &config_audioio_main::modified
        );

        connect(
            &rates, combo_changed,
            this, &config_audioio_main::modified
        );

        connect(
            &channels, spin_changed,
            this, &config_audioio_main::modified
        );

        connect(
            &buflen, spin_changed,
            this, &config_audioio_main::modified
        );
    };

    connect_change_notifiers();

    connect(
        &rates, combo_changed,
        this, &config_audioio_main::latency_event_with_int
    );

    connect(
        &buflen, spin_changed,
        this, &config_audioio_main::latency_event_with_int
    );

    refresh();
};
Exemplo n.º 3
0
int
main(int argc, char **argv)
{
  manitou_application app(argc,argv);
  gl_pApplication=&app;

#if defined(Q_OS_UNIX)  && !defined(Q_OS_MAC) 
  // The location of the data files depends on the prefix choosen at configure
  // time except under windows.
  QString s = QString(MANITOU_DATADIR);
  QString manitou_tr_path = s + "/translations";
  QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
  gl_xpm_path = s + "/icons";
  gl_help_path = s + "/help";
#elif defined(Q_OS_WIN)
  // under windows, the data directories are expected to be at the same level
  // than the executable file
  QString s = QApplication::applicationDirPath();
  QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
  QString manitou_tr_path = s + "/translations";
  gl_xpm_path = s + "/icons";
  gl_help_path = s + "/help";
#elif defined(Q_OS_MAC)
  // we use embedded resources on Mac
  QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
  gl_xpm_path = ":/images";
  QString manitou_tr_path = ":/translations";
#endif

  const char* cnx_string=NULL;
  QString conf_name;
  bool explicit_config=false;

  while(1) {
    int option_index = 0;
    static optstruct long_options[] = {
      {"debug-output", 1, 0, 'l'},
      {"debug-window", 1, 0, 'w'},
      {"config", 1, 0, 'c'},
      {"dbcnx", 1, 0, 'd'},
      {"help", 1, 0, 'h'},
      {0, 0, 0, 0}
    };

    int c = GETOPT_LONG(argc, argv, "d:c:h:", long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 0:
      printf ("option %s", long_options[option_index].name);
      if (OPTARG)
	printf (" with arg %s", OPTARG);
      printf ("\n");
      break;
    case '?':
      usage(argv[0]);
      break;
    case 'h':
      usage(argv[0]);
      break;
    case 'c':
      conf_name = OPTARG;
      explicit_config=true;
      break;
    case 'l':
      global_debug_level = OPTARG?atoi(OPTARG):10;
      break;
    case 'w':
      global_debug_level = OPTARG?atoi(OPTARG):10;
      global_debug_window = 1;
      break;
    case 'd':
      cnx_string = OPTARG;
      break;
    }
  }
  if (OPTIND < argc && !cnx_string) {
    /* compatibility with earlier versions: if there are non-named
       arguments on the command line, they will be interpreted as a
       connection string */
    cnx_string = argv[OPTIND];
  }

  QTranslator translator;
  QTranslator translator_qt;
  QLocale locale = QLocale::system();
  // search for a translation file, except for the C locale
  if (locale.name() != QLocale::c().name()) {
    if (translator_qt.load(QString("qt_")+locale.name(), qt_tr_path))
      app.installTranslator(&translator_qt);      
    if (translator.load(QString("manitou_")+locale.name(), manitou_tr_path)) {
      app.installTranslator(&translator);
    }
    else {
      QString tq = QString("manitou_")+locale.name();
      DBG_PRINTF(3, "Failed to load translation file %s", tq.toLocal8Bit().constData());
    }
  }

  if (conf_name.isEmpty()) {
    // then configuration is hostname-OSname
    QString hostname=QHostInfo::localHostName().toLower();
    if (hostname.isEmpty())
      hostname="unknown";
    QString uname;
#ifndef Q_OS_WIN
    struct utsname u;
    if (::uname(&u)==0 && u.sysname[0]) {
      uname = QString(u.sysname).toLower();
    }
#else
    uname="windows";
#endif
    conf_name = hostname + "-" + uname;
  }

  int connected=0;
  if (cnx_string==NULL) {
    // get the connection parameters from a dialog box
    QString qcs;
    login_dialog dlg;
    QSettings settings("Manitou-Mail", "manitou-ui");
    dlg.set_login(settings.value("login").toString());
    dlg.set_dbname(settings.value("dbname").toString());
    dlg.set_host(settings.value("host").toString());
    dlg.set_params(settings.value("params").toString());
    dlg.set_focus();
    do {
      if (dlg.exec()==1) {
	qcs = dlg.connect_string();
      }
      else {
	helper::close();
	exit(0); // exit if connection dialog closed with 'Cancel'
      }    
      QString errstr;
      if (!(connected=ConnectDb(qcs.toLocal8Bit(), &errstr))) {
	QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr);
      }
      else {
	settings.setValue("login", dlg.login());
	settings.setValue("dbname", dlg.dbnames()); // stringlist
	settings.setValue("host", dlg.host());
	settings.setValue("params", dlg.params());
      }
    } while (!connected);
  }
  else {
    QString errstr;
    if (!ConnectDb(cnx_string, &errstr)) {
      QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr);
      exit(1);
    }
  }

  if (!explicit_config) {
    QByteArray qb = conf_name.toLatin1();
    printf("Configuration used: %s\n", qb.constData());
    fflush(stdout);
  }

  global_conf.set_name(conf_name);
  global_conf.init();
  global_conf.apply();

  msgs_filter filter;
  filter.m_sql_stmt="0";

#ifdef Q_OS_UNIX
  gl_pApplication->setAttribute(Qt::AA_DontShowIconsInMenus, false);
#endif

  /* Instantiate the user in the database if necessary. Ideally we
     should ask for a fullname if not already known, but there's no
     GUI support for that yet */
  user::create_if_missing(QString::null);

  users_repository::fetch();
  message_port::init();
  msg_status_cache::init_db();

  msg_list_window* w = new msg_list_window(&filter,0);
  w->show();

  app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit()));
  app.connect(&app, SIGNAL(aboutToQuit()), SLOT(cleanup()));
  app.exec();
  DisconnectDb();
  DBG_PRINTF(1, "end");
  return 0;
}
Exemplo n.º 4
0
int
main(int argc, char **argv)
{
  manitou_application app(argc,argv);
  gl_pApplication=&app;

#if defined(Q_OS_UNIX)  && !defined(Q_OS_MAC) 
  // The location of the data files depends on the prefix choosen at configure
  // time except under windows.
  QString s = QString(MANITOU_DATADIR);
  QString manitou_tr_path = s + "/translations";
  QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
  gl_xpm_path = s + "/icons";
  gl_help_path = s + "/help";
#elif defined(Q_OS_WIN)
  // under windows, the data directories are expected to be at the same level
  // than the executable file
  QString s = QApplication::applicationDirPath();
  QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
  QString manitou_tr_path = s + "/translations";
  gl_xpm_path = s + "/icons";
  gl_help_path = s + "/help";
#elif defined(Q_OS_MAC)
  // we use embedded resources on Mac
  QString qt_tr_path = QLibraryInfo::location(QLibraryInfo::TranslationsPath);
  gl_xpm_path = ":/images";
  QString s = QApplication::applicationDirPath();
  gl_help_path = s + "/help";
  QString manitou_tr_path = s + "/translations";
#endif

  const char* cnx_string=NULL;
  QString conf_name;
  bool explicit_config=false;

  while(1) {
    int option_index = 0;
    static optstruct long_options[] = {
      {"debug-output", 1, 0, 'l'},
      {"debug-window", 1, 0, 'w'},
      {"config", 1, 0, 'c'},
      {"dbcnx", 1, 0, 'd'},
      {"help", 1, 0, 'h'},
      {0, 0, 0, 0}
    };

    int c = GETOPT_LONG(argc, argv, "d:c:h:", long_options, &option_index);
    if (c == -1)
      break;
    switch (c) {
    case 0:
      printf ("option %s", long_options[option_index].name);
      if (OPTARG)
	printf (" with arg %s", OPTARG);
      printf ("\n");
      break;
    case '?':
      usage(argv[0]);
      break;
    case 'h':
      usage(argv[0]);
      break;
    case 'c':
      conf_name = OPTARG;
      explicit_config=true;
      break;
    case 'l':
      global_debug_level = OPTARG?atoi(OPTARG):10;
      break;
    case 'w':
      global_debug_level = OPTARG?atoi(OPTARG):10;
      global_debug_window = 1;
      break;
    case 'd':
      cnx_string = OPTARG;
      break;
    }
  }
  if (OPTIND < argc && !cnx_string) {
    /* compatibility with earlier versions: if there are non-named
       arguments on the command line, they will be interpreted as a
       connection string */
    cnx_string = argv[OPTIND];
  }

  QTranslator translator;
  QTranslator translator_qt;
  QLocale locale = QLocale::system();
  // search for a translation file, except for the C locale
  if (locale.name() != QLocale::c().name()) {
    if (translator_qt.load(QString("qt_")+locale.name(), qt_tr_path))
      app.installTranslator(&translator_qt);
    if (translator.load(QString("manitou_")+locale.name(), manitou_tr_path)) {
      app.installTranslator(&translator);
    }
    else {
      QString tq = QString("manitou_")+locale.name();
      DBG_PRINTF(3, "Failed to load translation file %s", tq.toLocal8Bit().constData());
    }
  }

  if (conf_name.isEmpty()) {
    // then configuration is hostname-OSname
    QString hostname=QHostInfo::localHostName().toLower();
    if (hostname.isEmpty())
      hostname="unknown";
    QString uname;
#ifndef Q_OS_WIN
    struct utsname u;
    if (::uname(&u)==0 && u.sysname[0]) {
      uname = QString(u.sysname).toLower();
    }
#else
    uname="windows";
#endif
    conf_name = hostname + "-" + uname;
  }

  /* Call createUuid() before creating any window as a workaround
     against QTBUG-11080 or QTBUG-11213 in Qt-4.6.2 on Linux.
     Otherwise, createUuid() may return a UUID that is always the same
     when creating a new Message-Id later on. The fix for this Qt bug
     has not been backported in Ubuntu-10.04 LTS at this time
     (2012-10-08). */
  (void)QUuid::createUuid();

  if (cnx_string==NULL) {
    login_dialog dlg;
    if (dlg.exec() == QDialog::Rejected)
      return 0;
  }
  else {
    QString errstr;
    if (!ConnectDb(cnx_string, &errstr)) {
      QMessageBox::critical(NULL, QObject::tr("Fatal database error"), QObject::tr("Error while connecting to the database:\n")+errstr);
      return 1;
    }
  }

  if (!explicit_config) {
    printf("Configuration used: %s\n", conf_name.toLocal8Bit().constData());
  }

  global_conf.set_name(conf_name);
  global_conf.init();
  global_conf.apply();

  if (!QFile::exists(gl_xpm_path+"/"+FT_ICON16_QUIT)) {
    gl_pApplication->display_warning(QObject::tr("Icon files not found at: %1").arg(gl_xpm_path));
  }

  msgs_filter filter;
  QString sq = get_config().get_string("display/start_query");
  filter.m_sql_stmt= sq.isEmpty() ? "0" : sq;

#ifdef Q_OS_UNIX
  gl_pApplication->setAttribute(Qt::AA_DontShowIconsInMenus, false);
#endif

  users_repository::fetch();
  message_port::init();
  msg_status_cache::init_db();
  tags_repository::fetch();
  app.setup_desktop_tray_icon();

  msg_list_window* w = new msg_list_window(&filter,0);
  w->show();

  app.connect(&app, SIGNAL(lastWindowClosed()), SLOT(quit()));
  app.connect(&app, SIGNAL(aboutToQuit()), SLOT(cleanup()));
  app.exec();
  DisconnectDb();
  return 0;
}