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

main_mixer_window.cpp

//
// C++ Implementation:
//
// Description:
//
//
// Author: Sebastian Holtermann <sebholt@xwmw.org>, (C) 2010-2011
//
// Copyright: See COPYING file that comes with this distribution
//
//

#include "main_mixer_window.hpp"

#include <QVBoxLayout>
#include <QCoreApplication>
#include <QCloseEvent>

#include <QIcon>
#include <QFile>

#include "main_view_mixer_simple.hpp"
#include "main_view_mixer_ctl.hpp"
#include "main_view_info.hpp"
#include "dialog_info.hpp"
#include "dialog_alsa_config.hpp"

#include <iostream>


Main_Mixer_Window::Main_Mixer_Window (
      QWidget * parent_n,
      Qt::WindowFlags flags_n ) :
QMainWindow ( parent_n, flags_n ),
_device_iface ( 0 ),
_mixer_controls_tbar ( 0 ),
_view_type_tbar ( 0 ),
_view_type ( _num_view_types ),
_act_grp_tbar_vtype ( 0 ),
_view ( 0 ),
_setup_stage ( true ),
_selecting_ctl ( false ),
_is_minimized_in_tray ( false ),
_silent_close ( false ),
_force_close ( false ),
_fully_closed ( false )
{
      setWindowTitle ( PROGRAM_TITLE );
      setObjectName ( PROGRAM_TITLE );

      _view_names[0] = tr ( "Simple mixer" );
      _view_names[1] = tr ( "Element mixer" );
      _view_names[2] = tr ( "Control info" );

      // View type icons
      {
            const QString icon_path_base ( INSTALL_DIR_APP_ICONS );
            const char * fd_def[_num_view_types] = {
                  "multimedia-volume-control",
                  "preferences-desktop",
                  "audio-card"
            };
            for ( unsigned int ii=0; ii < num_view_types(); ++ii ) {
                  QString icon_path ( "/view-type-%1.svg" );
                  icon_path = icon_path.arg ( ii );
                  icon_path.prepend ( icon_path_base );
                  if ( QFile::exists ( icon_path ) ) {
                        _icons_vtype[ii] = QIcon ( icon_path );
                  } else {
                        _icons_vtype[ii] = QIcon::fromTheme ( fd_def[ii] );
                  }
            }
      }

      _key_seq_device = QKeySequence ( Qt::Key_F6 );
      _key_seq_mixer = QKeySequence ( Qt::Key_F7 );
      _key_seq_vtype = QKeySequence ( Qt::Key_F8 );


      // Init menus
      init_menus();
      init_toolbars();
      init_docks();
      init_mini_mixer();
      update_fullscreen_action();

      // Central view widget
      {
            QHBoxLayout * lay ( new QHBoxLayout );
            _wdg_view.setLayout ( lay );
      }
      setCentralWidget ( &_wdg_view );


      // Load settings and restore
      _settings.load();
      restoreState ( _settings.main_window_state );

      update_visibility_toolbars();
      update_visibility_tray_icon();

      _wdg_view.show();
}


Main_Mixer_Window::~Main_Mixer_Window ( )
{
      clear_view();
}


void
Main_Mixer_Window::init_menus ( )
{
      // Action: Exit / Quit
      QAction * act_quit = new QAction ( tr ( "&Quit" ), this );
      act_quit->setShortcut ( QKeySequence ( QKeySequence::Quit ) );
      act_quit->setIcon ( QIcon::fromTheme ( "application-exit" ) );
      act_quit->setIconVisibleInMenu ( true );

      // Action: Settings
      QAction * act_settings = new QAction ( tr ( "&Settings" ), this );
      act_settings->setShortcut ( QKeySequence ( tr ( "Ctrl+s" ) ) );
      act_settings->setIcon ( QIcon::fromTheme ( "preferences-desktop" ) );
      act_settings->setIconVisibleInMenu ( true );

      // Action: Refresh
      QAction * act_refresh = new QAction ( tr ( "&Refresh" ), this );
      act_refresh->setShortcut ( QKeySequence ( QKeySequence::Refresh ) );
      act_refresh->setIcon ( QIcon::fromTheme ( "view-refresh" ) );
      act_refresh->setIconVisibleInMenu ( true );


      // Action: Device selection
      _act_show_device = new QAction ( this );
      _act_show_device->setText ( tr ( "Show &device selection" ) );
      _act_show_device->setShortcut ( _key_seq_device );
      _act_show_device->setCheckable ( true );
      _act_show_device->setChecked ( _settings.show_device_selection );

      // Mixer tools
      _act_show_mixer_bar = new QAction ( this );
      _act_show_mixer_bar->setText ( tr ( "Show &mixer controls" ) );
      _act_show_mixer_bar->setShortcut ( _key_seq_mixer );
      _act_show_mixer_bar->setCheckable ( true );
      _act_show_mixer_bar->setChecked ( _settings.show_mixer_controls );

      // View type selection
      _act_show_vtype_bar = new QAction ( this );
      _act_show_vtype_bar->setText ( tr ( "Show &view type selection" ) );
      _act_show_vtype_bar->setShortcut ( _key_seq_vtype );
      _act_show_vtype_bar->setCheckable ( true );
      _act_show_vtype_bar->setChecked ( _settings.show_view_selection );


      _act_grp_menu_vtype = new QActionGroup ( this );
      {
            QAction * acts[num_view_types()];
            for ( unsigned int vii=0; vii < num_view_types(); ++vii ) {
                  acts[vii] = new QAction ( _act_grp_menu_vtype );
                  acts[vii]->setText ( _view_names[vii] );
                  acts[vii]->setCheckable ( true );
                  acts[vii]->setData ( vii );
                  acts[vii]->setToolTip ( _view_names[vii] );
            }

            acts[0]->setShortcut ( QKeySequence ( "1" ) );
            acts[1]->setShortcut ( QKeySequence ( "2" ) );
            acts[2]->setShortcut ( QKeySequence ( "3" ) );
      }


      // Action: Alsa configuration view
      _act_alsa_cfg = new QAction ( tr ( "&Alsa configuration" ), this );
      _act_alsa_cfg->setShortcut ( QKeySequence ( tr ( "Ctrl+c" ) ) );
      _act_alsa_cfg->setIcon ( QIcon::fromTheme ( "preferences-system" ) );
      _act_alsa_cfg->setIconVisibleInMenu ( true );


      // Action: Fullscreen
      _act_fullscreen = new QAction ( this );
      _act_fullscreen->setShortcut ( QKeySequence ( Qt::Key_F9 ) );
      _act_fullscreen->setCheckable ( true );
      _act_fullscreen->setIconVisibleInMenu ( true );


      // Action: Info
      QAction * act_info = new QAction ( tr ( "&Info" ), this );
      act_info->setShortcut ( QKeySequence ( QKeySequence::HelpContents ) );
      act_info->setIcon ( QIcon::fromTheme ( "help-about" ) );
      act_info->setIconVisibleInMenu ( true );


      // Menus
      {
            QMenu * cmenu = menuBar()->addMenu ( tr ( "&File" ) );
            cmenu->addAction ( act_settings );
            cmenu->addSeparator();
            cmenu->addAction ( act_quit );
      }
      {
            QMenu * cmenu = menuBar()->addMenu ( tr ( "&Mixer" ) );
            cmenu->addSeparator();
            cmenu->addAction ( act_refresh );
            _menu_mixer = cmenu;
      }
      {
            QMenu * cmenu = menuBar()->addMenu ( tr ( "&View" ) );
            cmenu->addAction ( _act_show_device );
            cmenu->addAction ( _act_show_mixer_bar );
            cmenu->addAction ( _act_show_vtype_bar );
            cmenu->addSeparator();
            cmenu->addActions ( _act_grp_menu_vtype->actions() );
            cmenu->addAction ( _act_alsa_cfg );
            cmenu->addSeparator();
            cmenu->addAction ( _act_fullscreen );
      }
      {
            QMenu * cmenu = menuBar()->addMenu ( tr ( "&Help" ) );
            cmenu->addAction ( act_info );
      }


      // Connect actions

    connect ( act_quit, SIGNAL ( triggered() ),
            this, SLOT ( force_close() ) );


      // View actions

      connect ( _act_show_device, SIGNAL ( toggled ( bool ) ),
            this, SLOT ( show_device_selection ( bool ) ) );

      connect ( _act_show_mixer_bar, SIGNAL ( toggled ( bool ) ),
            this, SLOT ( show_mixer_controls ( bool ) ) );

      connect ( _act_show_vtype_bar, SIGNAL ( toggled ( bool ) ),
            this, SLOT ( show_view_type_selection ( bool ) ) );


      connect ( _act_grp_menu_vtype, SIGNAL ( triggered ( QAction * ) ),
            this, SLOT ( view_type_action_triggered ( QAction * ) ) );

    connect ( _act_alsa_cfg, SIGNAL ( triggered() ),
            this, SLOT ( show_dialog_alsa_config() ) );


    connect ( act_refresh, SIGNAL ( triggered() ),
            this, SLOT ( refresh_data() ) );

    connect ( _act_fullscreen, SIGNAL ( toggled ( bool ) ),
            this, SLOT ( set_fullscreen ( bool ) ) );


      // Info action

    connect ( act_settings, SIGNAL ( triggered() ),
            this, SLOT ( show_dialog_settings() ) );

    connect ( act_info, SIGNAL ( triggered() ),
            this, SLOT ( show_dialog_info() ) );
}


void
Main_Mixer_Window::init_toolbars ( )
{
      _act_grp_tbar_vtype = new QActionGroup ( this );
      connect ( _act_grp_tbar_vtype, SIGNAL ( triggered ( QAction * ) ),
            this, SLOT ( view_type_action_triggered ( QAction * ) ) );

      _act_fullscreen_tbar = new QAction ( this );
      _act_fullscreen_tbar->setCheckable ( true );

    connect ( _act_fullscreen_tbar, SIGNAL ( toggled ( bool ) ),
            this, SLOT ( set_fullscreen ( bool ) ) );

      // View type toolbar
      {
            QAction * acts[num_view_types()];
            for ( unsigned int ii=0; ii < num_view_types(); ++ii ) {
                  acts[ii] = new QAction ( _act_grp_tbar_vtype );
                  acts[ii]->setCheckable ( true );
                  acts[ii]->setData ( ii );
                  acts[ii]->setToolTip ( _view_names[ii] );
                  acts[ii]->setIcon ( _icons_vtype[ii] );
            }
      }
      {
            _mixer_controls_tbar = new Mixer_Toolbar ( this );
            _mixer_controls_tbar->hide();
            _mixer_controls_tbar->setWindowTitle ( tr ( "View type" ) );
            _mixer_controls_tbar->setObjectName ( "mixer_tbar" );
            _mixer_controls_tbar->installEventFilter ( this );

            _mixer_controls_tbar->act_close()->setText ( tr ( "Hide mixer controls" ) );
            _mixer_controls_tbar->act_close()->setShortcut ( _key_seq_mixer );
      }
      {
            _view_type_tbar = new Mixer_Toolbar ( this );
            _view_type_tbar->hide();
            _view_type_tbar->setWindowTitle ( tr ( "View type" ) );
            _view_type_tbar->setObjectName ( "vtype_tbar" );
            _view_type_tbar->addActions ( _act_grp_tbar_vtype->actions() );
            //vtype_bar->addSeparator ();
            //vtype_bar->addAction ( _act_fullscreen_tbar );
            _view_type_tbar->installEventFilter ( this );

            _view_type_tbar->act_close()->setText ( tr ( "Hide view type selection" ) );
            _view_type_tbar->act_close()->setShortcut ( _key_seq_vtype );
      }

      addToolBar ( Qt::TopToolBarArea, _view_type_tbar );
      addToolBar ( Qt::TopToolBarArea, _mixer_controls_tbar );
}


void
Main_Mixer_Window::init_docks ( )
{
      _device_iface = new Device_Selection ( _mixer_style );
      _device_iface->hide();
      _device_iface->setWindowTitle ( tr ( "Device" ) );
      _device_iface->setObjectName ( "device_dock" );
      _device_iface->installEventFilter ( this );
      addDockWidget ( Qt::RightDockWidgetArea, _device_iface );

      connect ( _device_iface, SIGNAL ( sig_control_changed() ),
            this, SLOT ( select_ctl_from_side_iface() ) );

      _device_iface->act_close()->setText ( tr ( "Hide device selection" ) );
      _device_iface->act_close()->setShortcut ( _key_seq_device );
}


void
Main_Mixer_Window::init_mini_mixer ( )
{
      connect (
            &_mini_mixer, SIGNAL ( sig_activated() ),
            this, SLOT ( tray_icon_activation() ) );

      connect (
            &_mini_mixer, SIGNAL ( sig_show() ),
            this, SLOT ( tray_icon_activation() ) );

      connect (
            &_mini_mixer, SIGNAL ( sig_close() ),
            this, SLOT ( force_close() ) );
}


void
Main_Mixer_Window::update_fullscreen_action ( )
{
      QString txt;
      QIcon icon;
      bool checked;

      if ( isFullScreen() ) {
            txt = tr ( "Normal &screen" );
            icon = QIcon::fromTheme ( "view-restore" );
            checked = true;
      } else {
            txt = tr ( "Full&screen" );
            icon = QIcon::fromTheme ( "view-fullscreen" );
            checked = false;
      }

      _act_fullscreen->setText ( txt );
      _act_fullscreen->setIcon ( icon );
      _act_fullscreen->setChecked ( checked );

      _act_fullscreen_tbar->setText ( txt );
      _act_fullscreen_tbar->setIcon ( icon );
      _act_fullscreen_tbar->setChecked ( checked );
}


void
Main_Mixer_Window::clear_view ( )
{
      if ( _view != 0 ) {
            delete _view;
            _view = 0;
      }
}


void
Main_Mixer_Window::create_view ( )
{
      if ( view_type() == 0 ) {

            Main_View_Mixer_Simple * mview =
                  new Main_View_Mixer_Simple ( _settings, _current_ctl, this );
            mview->set_mixer_style ( &_mixer_style );

            connect ( mview, SIGNAL ( sig_settings_changed() ),
                  this, SLOT ( settings_changed_mixer() ) );

            _view = mview;

      } else if ( view_type() == 1 ) {

            Main_View_Mixer_CTL * mview =
                  new Main_View_Mixer_CTL ( _settings, _current_ctl, this );
            mview->set_mixer_style ( &_mixer_style );

            _view = mview;

      } else if ( view_type() == 2 ) {

            Main_View_Info * mview =
                  new Main_View_Info ( _current_ctl, this );
            mview->set_mixer_style ( &_mixer_style );

            _view = mview;
      }

      if ( _view != 0 ) {
            _wdg_view.layout()->addWidget ( _view );

            { // Menu actions
                  QList < QAction * > view_acts;
                  _view->acquire_menu_actions ( view_acts );
                  _menu_mixer->insertActions ( _menu_mixer->actions()[0], view_acts );
            }

            { // Toolbar actions
                  QList < QAction * > view_acts;
                  _view->acquire_toolbar_actions ( view_acts );
                  _mixer_controls_tbar->addActions ( view_acts );
            }
            update_visibility_toolbars();
      }
}


void
Main_Mixer_Window::reload_mini_mixer ( )
{
      QString dev_str;

      // Mini mixer
      if ( _settings.mini.device_mode == Mini_Mixer_Settings::DEV_DEFAULT ) {
            dev_str = _device_iface->default_ctl().ctl_id();
      } else if ( _settings.mini.device_mode == Mini_Mixer_Settings::DEV_CURRENT ) {
            dev_str = _current_ctl.ctl_id();
      } else if ( _settings.mini.device_mode == Mini_Mixer_Settings::DEV_USER ) {
            dev_str = _settings.mini.user_device;
      }

      _mini_mixer.set_wheel_degrees ( settings().wheel_degrees );
      _mini_mixer.set_ctl_address ( dev_str );
}


void
Main_Mixer_Window::enter_setup_stage ( )
{
      _setup_stage = true;

      clear_view();
}


void
Main_Mixer_Window::finish_setup_stage ( )
{
      _setup_stage = false;

      settings_changed_mixer();
      settings_changed_mini_mixer();

      create_view();

      if ( _view != 0 ) {
            _view->reload();
            _view->show();
      }
}


void
Main_Mixer_Window::select_view_simple_mixer ( )
{
      select_view_type ( 0 );
}


void
Main_Mixer_Window::select_view_element_mixer ( )
{
      select_view_type ( 1 );
}


void
Main_Mixer_Window::select_view_control_info ( )
{
      select_view_type ( 2 );
}


void
Main_Mixer_Window::select_view_type_int (
      int type_n )
{
      if ( ( type_n >= 0 ) ||
            ( type_n < (int)num_view_types() ) )
      {
            select_view_type ( (unsigned int)type_n );
      }
}


void
Main_Mixer_Window::select_view_type (
      unsigned int type_n )
{
      if ( ( _view_type == type_n ) ||
            ( type_n >= num_view_types() ) )
      {
            return;
      }

      if ( !setup_stage() ) {
            clear_view();
      }

      _view_type = type_n;
      _settings.view_type = type_n;

      _act_grp_menu_vtype->actions()[_view_type]->setChecked ( true );
      _act_grp_tbar_vtype->actions()[_view_type]->setChecked ( true );

      if ( !setup_stage() ) {
            create_view();
            if ( _view != 0 ) {
                  _view->reload();
                  _view->show();
            }
      }
}


void
Main_Mixer_Window::select_ctl (
      const QSnd::Snd_Control_Address & ctl_n )
{
      if ( !_selecting_ctl && ( _current_ctl != ctl_n ) ) {
            _selecting_ctl = true;
            _current_ctl = ctl_n;

            _device_iface->update_selected_ctl ( _current_ctl );

            if ( _view != 0 ) {
                  _view->reload();
            }

            if ( settings().mini.device_mode == Mini_Mixer_Settings::DEV_CURRENT ) {
                  reload_mini_mixer();
            }

            _selecting_ctl = false;
      }
}


void
Main_Mixer_Window::select_default_ctl ( )
{
      select_ctl ( _device_iface->default_ctl() );
}


void
Main_Mixer_Window::select_ctl_from_side_iface ( )
{
      select_ctl ( _device_iface->selected_ctl() );
}


void
Main_Mixer_Window::refresh_data ( )
{
      _device_iface->refresh_data();
      if ( _view != 0 ) {
            _view->reload_delayed();
      }
}


void
Main_Mixer_Window::set_fullscreen (
      bool flag_n )
{
      if ( flag_n != isFullScreen() ) {
            if ( flag_n ) {
                  showFullScreen();
            } else {
                  showNormal();
            }
            update_fullscreen_action();
      }
}



bool
Main_Mixer_Window::minimize_to_tray ( )
{
      if ( QSystemTrayIcon::isSystemTrayAvailable() ) {

            // Hide dialogs
            if ( _dialog_settings ) {
                  _dialog_settings->hide();
            }
            if ( _dialog_info ) {
                  _dialog_info->hide();
            }
            if ( _dialog_alsa_config ) {
                  _dialog_alsa_config->hide();
            }

            hide();

            _is_minimized_in_tray = true;
            _settings.is_tray_minimized = true;

            update_visibility_tray_icon();
            return true;
      }
      return false;
}


void
Main_Mixer_Window::raise_from_tray ( )
{
      if ( isMinimized() ) {
            showNormal();
      }
      show();
      raise();

      // Show dialogs
      if ( _dialog_settings ) {
            _dialog_settings->show();
      }
      if ( _dialog_info ) {
            _dialog_info->show();
      }
      if ( _dialog_alsa_config ) {
            _dialog_alsa_config->show();
      }

      _is_minimized_in_tray = false;
      _settings.is_tray_minimized = false;

      update_visibility_tray_icon();
}


void
Main_Mixer_Window::save_settings ( )
{
      _settings.main_window_state = saveState();
      _settings.write();
}


void
Main_Mixer_Window::silent_close ( )
{
      _silent_close = true;
      force_close();
}


void
Main_Mixer_Window::force_close ( )
{
      _force_close = true;
      close();
}


void
Main_Mixer_Window::show_device_selection (
      bool flag_n )
{
      if ( _settings.show_device_selection != flag_n ) {
            _settings.show_device_selection = flag_n;
            settings_changed_mixer();
      }
}


void
Main_Mixer_Window::show_mixer_controls (
      bool flag_n )
{
      if ( _settings.show_mixer_controls != flag_n ) {
            _settings.show_mixer_controls = flag_n;
            settings_changed_mixer();
      }
}


void
Main_Mixer_Window::show_view_type_selection (
      bool flag_n )
{
      if ( _settings.show_view_selection != flag_n ) {
            _settings.show_view_selection = flag_n;
            settings_changed_mixer();
      }
}


void
Main_Mixer_Window::toggle_device_selection ( )
{
      show_device_selection ( !_settings.show_device_selection );
}


void
Main_Mixer_Window::toggle_mixer_controls ( )
{
      show_mixer_controls ( !_settings.show_mixer_controls );
}


void
Main_Mixer_Window::toggle_view_type_selection ( )
{
      show_view_type_selection ( !_settings.show_view_selection );
}


void
Main_Mixer_Window::show_dialog_settings ( )
{
      if ( _dialog_settings == 0 ) {
            _dialog_settings = new Dialog_Settings ( _settings, this );
            _dialog_settings->setAttribute ( Qt::WA_DeleteOnClose );
            _dialog_settings->installEventFilter ( this );

            connect ( _dialog_settings, SIGNAL ( sig_settings_changed_mixer() ),
                  this, SLOT ( settings_changed_mixer() ) );

            connect ( _dialog_settings, SIGNAL ( sig_settings_changed_tray() ),
                  this, SLOT ( settings_changed_tray() ) );

            connect ( _dialog_settings, SIGNAL ( sig_settings_changed_mini() ),
                  this, SLOT ( settings_changed_mini_mixer() ) );

            adjust_dialog_size ( _dialog_settings, 2, 3 );
      }
      _dialog_settings->show();
}


void
Main_Mixer_Window::show_dialog_info ( )
{
      if ( _dialog_info == 0 ) {
            _dialog_info = new Dialog_Info ( this );
            _dialog_info->setAttribute ( Qt::WA_DeleteOnClose );
      }
      _dialog_info->show();
}


void
Main_Mixer_Window::show_dialog_alsa_config ( )
{
      if ( _dialog_alsa_config == 0 ) {
            Dialog_Alsa_Config * dialog ( new Dialog_Alsa_Config ( _settings.alsa_cfg, this ) );
            dialog->set_model ( &_device_iface->config_model() );

            _dialog_alsa_config = dialog;
            _dialog_alsa_config->setAttribute ( Qt::WA_DeleteOnClose );

            adjust_dialog_size ( _dialog_alsa_config, 4, 5 );
      }
      _dialog_alsa_config->show();
}


void
Main_Mixer_Window::adjust_dialog_size (
      QWidget * dialog_n,
      unsigned int numerator_n,
      unsigned int denominator_n )
{
      // Adjust dialog size
      const QSize shint ( dialog_n->sizeHint() );
      QSize snew (
            width() * numerator_n / denominator_n,
            height() * numerator_n / denominator_n );
      if ( snew.width() < shint.width() ) {
            snew.setWidth ( shint.width() );
      }
      if ( snew.height() < shint.height() ) {
            snew.setHeight ( shint.height() );
      }
      dialog_n->resize ( snew );
}


void
Main_Mixer_Window::view_type_action_triggered (
      QAction * act_n )
{
      if ( act_n == 0 ) {
            return;
      }

      const QVariant & vdata ( act_n->data() );
      if ( vdata.isValid() ) {
            if ( vdata.canConvert ( QVariant::UInt ) ) {
                  select_view_type ( vdata.toUInt() );
            }
      }
}

void
Main_Mixer_Window::settings_changed_mixer ( )
{
      if ( setup_stage() ) {
            return;
      }

      update_visibility_toolbars();
      update_settings_dialog();

      if ( _view != 0 ) {
            _view->apply_settings();
      }
}


void
Main_Mixer_Window::settings_changed_tray ( )
{
      update_visibility_tray_icon();
      update_settings_dialog();
}


void
Main_Mixer_Window::settings_changed_mini_mixer ( )
{
      update_visibility_tray_icon();
      update_settings_dialog();
      reload_mini_mixer();
}


void
Main_Mixer_Window::update_settings_dialog ( )
{
      if ( _dialog_settings != 0 ) {
            _dialog_settings->update_inputs();
      }
      _act_show_device->setChecked ( _settings.show_device_selection );
      _act_show_mixer_bar->setChecked ( _settings.show_mixer_controls );
      _act_show_vtype_bar->setChecked ( _settings.show_view_selection );
}


void
Main_Mixer_Window::parse_message (
      QString msg_n )
{
      //std::cout << "Main_Mixer_Window::parse_message " << "\n";

      enter_setup_stage();

      QStringList rows ( msg_n.split ( "\n", QString::SkipEmptyParts ) );

      for ( int ii=0; ii < rows.size(); ++ii ) {
            const QString & row ( rows[ii] );

            //std::cout << "row[" << ii << "]: " << row.toLocal8Bit().constData() << "\n";

            if ( row.contains ( "raise", Qt::CaseInsensitive ) ) {

                  if ( !isActiveWindow() ) {
                        raise_from_tray();
                  }

            } else if ( row.contains ( "ctl_address=", Qt::CaseInsensitive ) ) {

                  const int idx ( row.indexOf ( "=" ) + 1 );
                  QString sstr ( row.mid ( idx ).trimmed() );
                  if ( !sstr.isEmpty() ) {
                        select_ctl ( sstr );
                  }

            }
      }

      finish_setup_stage();
}


void
Main_Mixer_Window::tray_icon_activation ( )
{
      if ( isVisible() && isActiveWindow() ) {
            minimize_to_tray();
      } else {
            raise_from_tray();
      }
}


void
Main_Mixer_Window::keyPressEvent (
      QKeyEvent * event_n )
{
      QMainWindow::keyPressEvent ( event_n );
      const QKeySequence kseq ( event_n->key() );
      if ( kseq == _key_seq_device ) {
            toggle_device_selection();
      } else if ( kseq == _key_seq_mixer ) {
            toggle_mixer_controls();
      } else if ( kseq == _key_seq_vtype ) {
            toggle_view_type_selection();
      }
}


void
Main_Mixer_Window::contextMenuEvent (
      QContextMenuEvent * event_n )
{
      if ( _context_menu != 0 ) {
            if ( _context_menu->isVisible() ) {
                  return;
            }
      }

      QList < QAction * > acts;
      if ( _view != 0 ) {
            _view->acquire_context_actions ( acts );
      }

      if ( acts.size() > 0 ) {
            _context_menu = new QMenu ( this );
            _context_menu->setAttribute ( Qt::WA_DeleteOnClose );
            _context_menu->addActions ( acts );
            _context_menu->popup ( event_n->globalPos() );
      }
}


void
Main_Mixer_Window::changeEvent (
      QEvent * event_n )
{
      QMainWindow::changeEvent ( event_n );

      if ( event_n->type() == QEvent::WindowStateChange ) {
            QWindowStateChangeEvent * wst_ev (
                  dynamic_cast < QWindowStateChangeEvent * > ( event_n ) );
            if ( wst_ev != 0  ) {
                  if ( settings().tray_on_minimize &&
                        ( settings().show_tray_icon != Mixer_Settings::TRAY_ICON_NEVER ) &&
                        ( ( windowState()      & Qt::WindowMinimized ) != 0 ) &&
                        ( ( wst_ev->oldState() & Qt::WindowMinimized ) == 0 ) )
                  {
                        minimize_to_tray();
                  }
            }
      }
}


void
Main_Mixer_Window::closeEvent (
      QCloseEvent * event_n )
{
      //std::cout << "Main_Mixer_Window::closeEvent()" << "\n";

      QMainWindow::closeEvent ( event_n );

      bool full_close ( true );

      const bool try_to_minimize (
            !_force_close &&
            !_fully_closed &&
            settings().tray_on_close &&
            ( settings().show_tray_icon != Mixer_Settings::TRAY_ICON_NEVER ) );
      if ( try_to_minimize ) {
            if ( minimize_to_tray() ) {
                  full_close = false;
            }
      }

      if ( full_close && !_fully_closed ) {
            _fully_closed = true;
            save_settings();
            if ( !_silent_close ) {
                  emit sig_full_close();
            }
      }
}


bool
Main_Mixer_Window::eventFilter (
      QObject * obj_n,
      QEvent * event_n )
{
      bool filtered ( false );
      if ( obj_n == _dialog_settings ) {

            if ( event_n->type() == QEvent::KeyPress ) {
                  QKeyEvent * ev_kp (
                        dynamic_cast < QKeyEvent * > ( event_n ) );
                  if ( ev_kp != 0 ) {
                        filtered = true;
                        const QKeySequence kseq ( ev_kp->key() );
                        if ( kseq ==_key_seq_device ) {
                              toggle_device_selection();
                        } else if ( kseq == _key_seq_mixer ) {
                              toggle_mixer_controls();
                        } else if ( kseq == _key_seq_vtype ) {
                              toggle_view_type_selection();
                        } else {
                              filtered = false;
                        }
                  }
            }

      } else if ( obj_n == _device_iface ) {
            if ( event_n->type() == QEvent::Close ) {
                  show_device_selection ( false );
            }
      } else if ( obj_n == _mixer_controls_tbar ) {
            if ( event_n->type() == QEvent::Close ) {
                  show_mixer_controls ( false );
            }
      } else if ( obj_n == _view_type_tbar ) {
            if ( event_n->type() == QEvent::Close ) {
                  show_view_type_selection ( false );
            }
      }
      return filtered;
}


void
Main_Mixer_Window::update_visibility_toolbars ( )
{
      if ( _view_type_tbar != 0 ) {
            _view_type_tbar->setVisible ( settings().show_view_selection );
      }
      if ( _mixer_controls_tbar != 0 ) {
            const bool show_bar (
                  settings().show_mixer_controls &&
                  ( _mixer_controls_tbar->actions().size() > 0 ) );
            _mixer_controls_tbar->setVisible ( show_bar );
      }
      if ( _device_iface != 0 ) {
            _device_iface->setVisible ( settings().show_device_selection );
      }
}


void
Main_Mixer_Window::update_visibility_tray_icon ( )
{
      bool show_icon ( false );
      const unsigned int sti ( _settings.show_tray_icon );
      if ( sti == Mixer_Settings::TRAY_ICON_ALWAYS ) {
            show_icon = true;
      } else if (
            ( sti == Mixer_Settings::TRAY_ICON_MINIMIZED ) &&
            is_minimized_in_tray() )
      {
            show_icon = true;
      }

      _mini_mixer.show_tray_icon ( show_icon );
      _mini_mixer.set_show_balloon ( settings().mini.show_balloon );
      _mini_mixer.set_balloon_lifetime ( settings().mini.balloon_lifetime );
}


Generated by  Doxygen 1.6.0   Back to index