📄 qmmainwindow.cpp
字号:
ret = false; } m_pContinueHere = 0; return ret;}/*! \returns The number of the song currently playing, counting from 0. -1 if no song playing.*/intQmMainWindow::playListPosition() { return activePlayList()->position();}/*! Deletes the song at the requested position if it exists, else ignores it.*/voidQmMainWindow::playListDeletePosition( int pos){ activePlayList()->deletePosition(pos);}/*! Plays the song at position \a pos of the active play list. Ignored if the position is out of range.*/voidQmMainWindow::playListPosition( int pos){ QmSongItem *tsong = song(pos); if (tsong) selected(tsong, activePlayList());}/*! \return Number of songs in the active play list.*/intQmMainWindow::playListEntries(){ return activePlayList()->noSongs();}/*! \return Number of seconds the current song has played, or -1 if nothing is playing.*/intQmMainWindow::currentSongPlayedTime(){ return m_pStatusBar->secondsPlaying();}/*! \return the file name with path of the current play list. The empty string there is no file name.*/const QString&QmMainWindow::playListFile(){ return m_pPlayList->filename();}/*! \return the volume. From linux it seems to be in the range 0 .. 127, possibly 0 .. 31*/intQmMainWindow::volume() const{ return QmMixer::instance()->volume();}/*! Apollo doesn't support changing the balanse, but can read it (go figure). \return something weird: look at the code. \todo look at this */intQmMainWindow::volumeBalanse() const{ return QmMixer::instance()->balance();}/*! Session management. Saves which play list is currently loaded, which song it's at, any play first songs, position and size of windows, etc. \todo Qt has special support for session management. May be something to look at (ms)*/voidQmMainWindow::saveState(){ QmConfig *conf = QmConfig::instance(); // save playfirst.xml QString pf(QDir::homeDirPath() + "/.apollo/playfirst.xml"); if (m_pPlayFirst->isEmpty()) { QFileInfo fi(pf); if (fi.exists() && fi.isFile()) { QDir dir(QDir::homeDirPath() + "/.apollo"); dir.remove("playfirst.xml"); } } else { m_pPlayFirst->saveAsXml(pf); } if (m_pPlayList->isDirty()) saveStartupPlayList(); else conf->set("path", "startup-playlist", m_pPlayList->filename()); // Store current song being played, if any if (m_pPlayList->currentSong()) conf->set( "main-window", "playing-song", m_pPlayList->currentSong()->filePath() ); else conf->set( "main-window", "playing-song", "" ); conf->set("path", "startup-playlisttree", m_pBrowser->playTreeFile()); // save window/pane geometry conf->set( "main-window", "geometry", QRect( pos(), size() ) ); conf->set( "main-window", "scroll-pos", QPoint( m_pPlayList->contentsX(), m_pPlayList->contentsY() ) ); QValueList<int> widths = m_pListBrowserSplitter->sizes(); if ( widths.count() != 2 ) std::cerr << "QmMainWindow::saveState(): Not two elements in the main-window splitter?" << std::endl; else { if (m_Position == LeftBrowser || m_Position == TopBrowser) { conf->set( "main-window", "browser-width", *widths.at(0)); conf->set( "main-window", "playlist-width", *widths.at(1)); } else { conf->set( "main-window", "browser-width", *widths.at(1)); conf->set( "main-window", "playlist-width", *widths.at(0)); } } m_pPlayFirstHolder->show(); widths = m_pListsSplitter->sizes(); conf->set( "main-window", "playfirst-height", *widths.at(0)); conf->set( "main-window", "playlist-height", *widths.at(1)); conf->set( "main-window", "browser-position", m_Position); conf->set( "stuff", "loop", m_Loopp ); conf->set( "stuff", "loop-one", m_LoopOnep ); conf->set( "stuff", "random", m_Randomp ); m_pControlBar->save();}/*! Session management. Restores play mode, play list, playlist trees, directory tree, play first.*/voidQmMainWindow::restoreState(){ QmConfig *conf = QmConfig::instance(); conf->get( "stuff", "random", m_Randomp ); conf->get( "stuff", "loop", m_Loopp ); conf->get( "stuff", "loop-one", m_LoopOnep ); m_pControlBar->updateControls(); // create the short-cut manager so the shortcuts are installed. QmAccelManager::instance(); bool initvalSystray; conf->get( "stuff", "systray", initvalSystray ); QmSystray::show( this, initvalSystray ); QString tree = QmConfig::instance()->getString("path", "startup-playlisttree"); if (!tree.isEmpty() && QFile::exists(tree)) m_pBrowser->loadPlayListTree(tree); // read playfirst.xml QString pf(QDir::homeDirPath() + "/.apollo/playfirst.xml"); if (QFile::exists(pf)) { m_pPlayFirst->appendList(pf); showOrHidePlayFirst(); } loadStartupPlayList();} /*! Used on startup to load the play list used on the previous shut-down, and restores the currently playing song.*/voidQmMainWindow::loadStartupPlayList(){ if(QmRecoveryManager::instance()->loadingEnabled(QmConfig::PlayList) == false) return; setState( Busy ); // Restore playlist QmConfig *conf = QmConfig::instance(); QFileInfo playlist(conf->getString("path", "startup-playlist")); if ( playlist.exists() ) { m_pPlayList->loadPlayList( playlist.filePath() ); // Restore last playing song QmSongItem *songitem = m_pPlayList->findSong(conf->getString( "main-window", "playing-song" )); if (songitem) { songitem->setPlaying(true); m_pPlayList->setCurrent(songitem); m_pPlayList->setSelected(songitem, true); m_pPlayList->setCurrentItem(songitem); m_pPlayList->ensureItemVisible(songitem); } else { QPoint scroll_pos = conf->getPoint( "main-window", "scroll-pos" ); m_pPlayList->setContentsPos( scroll_pos.x(), scroll_pos.y() ); m_pPlayList->setColumnWidth( 0, m_pPlayList->visibleWidth() - m_pPlayList->columnWidth(1) ); m_pPlayList->triggerUpdate(); } } setState( Ready ); m_pControlBar->updateControls();}/*! Stores the current playlist in an internal file for playlist persistence and stores the current playing song in the config.*/voidQmMainWindow::saveStartupPlayList(){ setState( Busy ); // Store playlist QmConfig *conf = QmConfig::instance(); conf->set("path", "startup-playlist", QDir::homeDirPath() + "/.apollo/playlist.xml"); m_pPlayList->saveAsXml(conf->getString("path", "startup-playlist")); setState( Ready );}/*! Pauses if already playing, else starts a new one from PlayFirst, Random, ContinueHere, selected playlist item or top of playlist; in that preference order. \sa stop(), pause()*/voidQmMainWindow::play(){ if (m_PlayState==Paused || m_pPlayer->isPlaying()) pause(); else if (!m_pPlayFirst->isEmpty()) playAndUpdateControls(dynamic_cast<QmSongItem*>(m_pPlayFirst->pop())); else if (m_pPlayList->currentSong() == 0) { stop(); QmMainWindow::mainwin->statusUpdate(new Message(Message::Status, "No non-bad songs in playlist")); } else if (m_Randomp) selected(m_pPlayList->randomSong(), m_pPlayList); else if (m_ContinueHerep) { if (!tryContinueHere()) play(); } else selected(m_pPlayList->currentSong());} /*! Stops the music. \sa play(), pause()*/voidQmMainWindow::stop(){ m_StopClicked = true; m_pPlayer->stop(); setPlayingState( QmMainWindow::Stopped ); m_pControlBar->setPauseEnabled(false); m_pControlBar->setStopEnabled(false); m_pControlBar->updateControls();}/*! Toggle pause / play \todo blink play button or something \sa play(), stop()*/voidQmMainWindow::pause(){ if (m_PlayState==Paused || m_PlayState==Playing) { m_pPlayer->pause(); m_PlayState = m_PlayState==Paused ? Playing : Paused; m_pStatusBar->showSongInfo(); } m_pControlBar->updateControls();}/*! Selectes the previous song item, if any, and plays it, unless there is items in PlayFirst. Folder items and bad songs will be skipped. \sa next()*/voidQmMainWindow::prev(){ if (!m_pPlayFirst->isEmpty() || m_pPlayList->isEmpty() || m_Randomp) { statusUpdate(new Message(Message::Bug, "Can't use prev when there is songs in PlayFirst, " "PlayList is empty or random mode is on")); return; } if ( playingState() == QmMainWindow::Stopped ) play(); else selected(m_pPlayList->prevSong(m_Loopp)); }/*! Plays next song, if any, in this preference order - PlayFirst - Random - ContinueHere - PlayList \sa prev()*/voidQmMainWindow::next(){ if (m_PlayState == Stopped) { play(); return; } QListViewItem* tmp = 0; QmSongItem* tmp2; if (!m_pPlayFirst->isEmpty() && (tmp=m_pPlayFirst->pop())) playAndUpdateControls(dynamic_cast<QmSongItem*>(tmp)); else if (m_LoopOnep && m_pPlayList->currentSong()) selected(m_pPlayList->currentSong()); else if (m_Randomp && !m_pPlayList->isEmpty()) selected(m_pPlayList->randomSong(), m_pPlayList); else if (m_ContinueHerep) { if (!tryContinueHere()) next(); } else if ( playingState() != QmMainWindow::Stopped ) { if ((tmp2 = m_pPlayList->nextSong(m_Loopp))) selected(tmp2); else stop(); } else if (m_pPlayList->currentSong()) selected(m_pPlayList->currentSong()); else stop();}/*! The current random mode selects a song at random every time a new song is needed. There is no history. \todo implement history*/voidQmMainWindow::toggleRandomMode(){ m_Randomp = !m_Randomp; m_pControlBar->updateControls();}/*! Toggles loop mode on/off. */voidQmMainWindow::cycleLoopMode(){ if (m_Loopp) { m_Loopp = false; m_LoopOnep = true; } else if (m_LoopOnep) m_Loopp = m_LoopOnep = false; else m_Loopp = true; m_pControlBar->updateControls();}/*! Calls selected(item, playlist) with the play list as \a playlist. */voidQmMainWindow::selected( QListViewItem *Item) { selected(Item, m_pPlayList);}/*! Invoked to play a song from the play list. Called when an item has been selected in the play list (typically by double-clicking or pressing return), and from play(), and next(). If \a item is a: - Non-bad song it's meta info (id3 data for mp3s) is updated, and it's played, or put in the PlayFirst list if that is non-empty. - bad song, a message saying so is put on the status bar. - directory it is ignored.*/voidQmMainWindow::selected( QListViewItem *item, QmPlayList *playlist){ assert(item && dynamic_cast<QmPlayListItem*>(item)); if (!reinterpret_cast<QmPlayListItem*>(item)->isSong()) return; QmSongItem *song = reinterpret_cast<QmSongItem*>(item); if (song->isBad()) { statusUpdate(new Message(Message::Status, "%s is marked bad", song->text(0).latin1())); return; } if (song->artist().isEmpty()) song->readInfo(QmConfig::instance()->getString("stuff", "display-format").latin1(), QmConfig::instance()->getString("stuff", "display-format-multi").latin1()); if (!m_pPlayFirst->isEmpty()) { addToPlayFirst(song); return; } if (!QFile::exists(song->filePath())) { QmMainWindow::mainwin->statusUpdate(new Message(Message::Status, "Song doesn't exist: %s", song->filePath().latin1())); return; } playlist->setCurrent(song); playlist->setCurrentItem(song); playAndUpdateControls(song);}/*! hides PlayFirst if it's empty, called from PlayFirst*/voidQmMainWindow::showOrHidePlayFirst(){ if (m_pPlayFirst->isEmpty() == m_pPlayFirstHolder->isVisible()) { if (m_pPlayFirst->isEmpty()) m_pPlayFirstHolder->hide(); else { // ms: Personally, I don't see a use for the playfirst to have focus. // Almost always, I find myself wanting to continue using the keyboard // in the playlist. So, set the focus back to the previous widget // after showing the playfirst list. QWidget *hadfocus = qApp->focusWidget(); m_pPlayFirstHolder->show(); if(hadfocus) hadfocus->setFocus(); } m_pListsSplitter->refresh(); }}/*! Plays the song and updates the gui controls accordingly. This should be the only way to get a song playing, and thus allow for other side-effects such as logging or informing other programs. Called through selected.*/voidQmMainWindow::playAndUpdateControls( QmSongItem *song){ CHECK_PTR(song); m_StopClicked = false; // to distinguish end-of-song and click m_pStatusBar->clearName(); m_pStatusBar->clearTime(); m_pPlayer->play(song->filePath()); setPlayingState( QmMainWindow::Playing ); m_pControlBar->updateControls(); m_pStatusBar->showSongInfo(); m_pStatusBar->setSongTitle(song->displayString());}/*! Disables the play button if a folder is selected and we would have played the selected item (not in random mode, playfirst empty). \a item is a play list item.*/voidQmMainWindow::current( QListViewItem *item){ QmPlayListItem *thing = dynamic_cast<QmPlayListItem*>(item); if ( thing && (m_Randomp || !m_pPlayFirst->isEmpty() || !thing->isBad()) ) m_pControlBar->setPlayEnabled(true); else m_pControlBar->setPlayEnabled(false);}/*! This will be called whenever the player stops playing. This can happen three ways: <ul> <li> End of song reached. <li> User pushed stop, leading stop() to be called. <li> Stop is received through the remote-control socket, leading stop() to be called. </ul> In case the end of song was reached, we want to start loading the next song. We do \e not want to do that if stop is pushed. This function takes care of both these issues. \sa stop()*/voidQmMainWindow::playingStopped(){ if ( m_StopClicked ) setPlayingState( QmMainWindow::Stopped ); else next();}/*! Clears the play list.*/voidQmMainWindow::clearPlayList(){ m_pContinueHere = 0; m_pPlayList->clear(); m_pControlBar->updateControls();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -