예제 #1
0
AudioPlayer::AudioPlayer(Library* library, Backend backend, bool testing, QObject* parent)
    : QObject(parent)
    , library_(library)
    , mainWindow_(nullptr)
    , replaygain_(ReplayGainMode::None)
    , preamp_with_rg_(10)
    , playbackOrder_(PlaybackOrder::Default)
    , lengthHack_(false)
    , testing_(testing)
{
    if (backend == Backend::mpv)
        audioOutput_.reset(new MpvAudioOutput);
    else
        audioOutput_.reset(new PhononAudioOutput);
    QObject::connect(audioOutput_.get(), SIGNAL(aboutToFinish()), this, SLOT(aboutToFinish()));
    QObject::connect(audioOutput_.get(), SIGNAL(currentSourceChanged()), this, SLOT(currentSourceChanged()));
    QObject::connect(audioOutput_.get(), SIGNAL(tick(qint64)), this, SLOT(slotTick(qint64)));
    QObject::connect(audioOutput_.get(), SIGNAL(stateChanged(AudioState)), this, SLOT(slotAudioStateChanged(AudioState)));
    QObject::connect(audioOutput_.get(), SIGNAL(finished()), this, SLOT(slotFinished()));
    QObject::connect(audioOutput_.get(), SIGNAL(durationChanged(double)), this, SLOT(durationChanged(double)));
    QObject::connect(audioOutput_.get(), SIGNAL(metadataChanged(QString, QString, int)), this, SLOT(metadataChanged(QString, QString, int)));
    // Not using Phono totalTimeChanged() signal because it returns 0 when used with enqueue()
    // TODO: report bug to phonon
//    QObject::connect(audioOutput_, SIGNAL(totalTimeChanged(qint64)), this, SLOT(totalTimeChanged(qint64)));
    readSettings();
    instance = this;
}
예제 #2
0
MainWindow::MainWindow(AudioPlayer &player, QWidget *parent)
    : QMainWindow(parent),
      statusBar_(this),
      player_(player),
      cursorFollowsPlayback_(false),
      saveTabs_(false) {
    setupUi(this);
    // Not saving a pointer to this
    QActionGroup *playbackOrderGroup = new QActionGroup(this);
    playbackOrderGroup->addAction(defaultAction);
    playbackOrderGroup->addAction(randomAction);
    playbackOrderGroup->addAction(repeatTrackAction);
    playbackOrderGroup->addAction(repeatPlaylistAction);
    installEventFilter(this);

    player.setMainWindow(this);

    QObject::connect(&player_, SIGNAL(playbackOrderChanged(PlaybackOrder)), this,
                     SLOT(playbackOrderChanged(PlaybackOrder)));
    QObject::connect(&player_, SIGNAL(audioStateChanged(AudioState)), this,
                     SLOT(slotAudioStateChanged(AudioState)));
    QObject::connect(&player_, SIGNAL(trackPlaying(PTrack)), this, SLOT(updateUI(PTrack)));
    playbackOrderChanged(player.playbackOrder());

    QObject::connect(&player_, SIGNAL(tick(qint64)), this, SLOT(tick(qint64)));
    seekSlider_ = new SeekSlider(player_, this);
    volumeSlider_ = new QSlider(this);
    volumeSlider_->setOrientation(Qt::Horizontal);
    volumeSlider_->setMaximum(100);
    volumeSlider_->setMinimum(0);
    volumeSlider_->setValue(player_.volume() * 100);
    volumeSlider_->setSizePolicy(QSizePolicy::Maximum, QSizePolicy::Maximum);
    QObject::connect(volumeSlider_, SIGNAL(valueChanged(int)), this, SLOT(volumeChanged(int)));
    mainToolBar->addWidget(seekSlider_);
    mainToolBar->addWidget(volumeSlider_);

    trayIcon_ = new QSystemTrayIcon(this);
    setTrayIcon(false);
    connect(trayIcon_, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this,
            SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
    trayIcon_->show();

    setStatusBar(&statusBar_);
    QObject::connect(&statusBar_, SIGNAL(statusBarDoubleClicked()), this,
                     SLOT(statusBarDoubleClicked()));

    lyricsDock_ = new QDockWidget("Lyrics", this);
    // Not setting an object name because we don't want save its state
    // since Qt doesn't restore it correctly
    //     lyricsDock_->setObjectName("LyricsDock");
    lyricsWidget_ = new QPlainTextEdit(lyricsDock_);
    //     lyricsWidget_->setObjectName("LyricsWidget");
    lyricsWidget_->setReadOnly(true);
    lyricsDock_->setWidget(lyricsWidget_);
    QObject::connect(lyricsDock_, SIGNAL(visibilityChanged(bool)), this,
                     SLOT(dockVisibilityChanged(bool)));

    //     playlistTabs->setTabsClosable(true);
    QObject::connect(playlistTabs, SIGNAL(tabCloseRequested(int)), this,
                     SLOT(removePlaylistTab(int)));
    QObject::connect(playlistTabs, SIGNAL(newTabRequested()), this, SLOT(newTabRequested()));

    QObject::connect(menu_File, SIGNAL(aboutToShow()), this, SLOT(menuFileAboutToShow()));

    setWindowIcon(QIcon(":/icon/logo22.png"));

    instance = this;

    console_ = new ConsoleWindow(this);
    QObject::connect(console_, SIGNAL(visibilityChanged(bool)), this,
                     SLOT(consoleVisibilityChanged(bool)));

    readSettings();

    config_.set("mainwindow.save_tabs", QVariant(saveTabs_));
    QObject::connect(&config_, SIGNAL(keySet(QString, QVariant)), this,
                     SLOT(configChanged(QString, QVariant)));

    setShortcuts();
}